Listitem不會從數據庫中檢索。它從另一個班級轉移過來。我將如何從listview中刪除listitem?
0
A
回答
3
您不「從列表視圖中刪除listitem」。您修改支持ListView
的ListAdapter
所擁有的數據。如果適配器是ArrayAdapter
,請致電remove()
ArrayAdapter
。如果適配器是CursorAdapter
,請從數據庫中刪除該項並requery()
Cursor
。等等。
+0
你可以給一個示例代碼? – User358218 2010-08-27 02:48:29
0
更好,如果你使用),一個SimpleAdapter它可以通過消除要刪除&只是調用adapter.notifyDataSetChanged(什麼需要一個ArrayList.Then您更新列表一樣:
static final ArrayList<HashMap<String,String>> list =new ArrayList<HashMap<String,String>>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newentrypagelayout);
//create base adapter for listview
adapter= new SimpleAdapter(
this,
list,
R.layout.custom_list_row,
new String[] {"pen","price","color"},
new int[] {R.id.text1,R.id.text2, R.id.text3}
);
populateList();
setListAdapter(adapter);
}
public void populateList()
{
sHashMap<String,String> temp = new HashMap<String,String>();
temp.put("pen","MONT Blanc");
temp.put("price", "200.00$");
temp.put("color", "Silver, Grey, Black");
list.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("pen","Gucci");
temp1.put("price", "300.00$");
temp1.put("color", "Gold, Red");
list.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("pen","Parker");
temp2.put("price", "400.00$");
temp2.put("color", "Gold, Blue");
list.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("pen","Sailor");
temp3.put("price", "500.00$");
temp3.put("color", "Silver");
list.add(temp3);
HashMap<String,String> temp4 = new HashMap<String,String>();
temp4.put("pen","Porsche Design");
temp4.put("price", "600.00$");
temp4.put("color", "Silver, Grey, Red");
list.add(temp4);
}
now if you need to delete an item.Get the selected index(the item that has been selected) remove it from the array list & call the method I told before.Like:
public void itemDeleteButtonClicked(View v)
{
int index=itemsListView.getSelectedItemPosition();
list.remove(index);
adapter.notifyDataSetChanged();
}
相關問題
- 1. 從按鈕上的嵌套ListView中刪除ListItem點擊
- 2. 從jQuery移動listview動態刪除listitem刷新問題
- 3. 我如何刪除ListView中的項目?
- 4. listitem - 刪除 - 動態
- 5. 如何從ListView中刪除項目
- 6. 如何從listView中刪除項目?
- 7. 如何返回已被刪除的listitem?
- 8. 如何從listview刪除命令上的listview中刪除選定的記錄?
- 9. 如何從ListView中刪除項目而不從數據庫中刪除項目?
- 10. 如何從ListView C#刪除多個項目與刪除按鈕
- 11. 從SharedPreferences刪除ListView選項
- 12. 在cursoradapter中從ListView中刪除項目
- 13. 在addListener中從ListView中刪除項目
- 14. 如何刪除Listview中的邊框?
- 15. Asp.Net ListView如何刪除一行而不從數據源中刪除
- 16. 如何從android中的listview中刪除特定的行?
- 17. 我如何從圖中刪除效果
- 18. 我如何從wp_list_pages()中刪除https
- 19. 我如何從Powershell中刪除簽名?
- 20. 我如何從Qtreeview中刪除項目?
- 21. 我如何從Jekyll中刪除時區?
- 22. 如何從我的gitconfig中刪除url.git?
- 23. 從ListView中刪除所選項目
- 24. 從ListView中永久刪除項目
- 25. 從listview中刪除Sharepoint列表項?
- 26. 無法從WinForms中刪除項目ListView
- 27. 從Android的ListView中刪除項目
- 28. 從ListView中刪除所選項目
- 29. Android:從ListView中刪除項目
- 30. Android:從ListView/ArrayAdapter中刪除項目
請詳細說明你的問題? – Praveen 2010-08-25 09:36:21
lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice,lvItems)); \t \t \t \t \t lView.setChoiceMode(ListView.CHOICE_MODE_SINGLE) 我的列表項數組中:private string lvItems [] = { 「隨收隨付你漫遊」, 「國際漫遊」}; () public void remove() pos = lView.getCheckedItemPosition(); 如果(POS == 0){ \t/*刪除項目* /}} –
User358218
2010-08-27 01:24:15
我希望除去該特定項目時 [如果(POS == 0)] POS = lView.getCheckedItemPosition() ; – User358218 2010-08-27 01:29:49