2
我在視圖中使用了一個列表視圖,我希望當用戶選擇一個列表項時,應該在用戶選擇其他列表項或返回到「Listview」活動時保持選中狀態。這怎麼可能?在列表視圖中獲取所選項目
我在視圖中使用了一個列表視圖,我希望當用戶選擇一個列表項時,應該在用戶選擇其他列表項或返回到「Listview」活動時保持選中狀態。這怎麼可能?在列表視圖中獲取所選項目
嘗試這樣
simpleAdapter = new SimpleAdapter(this, docList, R.layout.your_layout,
new String[] { "UserName", "Status"}, new int[] {
R.id.username, R.id.status});
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
registerForContextMenu(listView);
listView.showContextMenu();
tv = (TextView) arg1.findViewById(R.id.username);
getListName = tv.getText().toString();
tv1 = (TextView) arg1.findViewById(R.id.status);
getFriendUserId = tv1.getText().toString();
}
});
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0,
View arg1, int position, long arg3)
{
String selectedItem = list.getSelectedItem().toString();
});
這裏selectedItem包含你在列表中選擇的內容。
我不想這樣,我想,當我從列表中選擇一個ITEN然後開放數據用於該項目,現在當我回來到該列表,則該項目之前被選中的名單必須在該名單中預選。 –
爲什麼你要在項目點擊中註冊上下文菜單的ListView,嚴重的是這個片段太錯誤了。 – xmen