Android ListView删除项目
如何删除ListView中的项?我没有找到删除函数Android ListView删除项目,android,listview,Android,Listview,如何删除ListView中的项?我没有找到删除函数 ShopList = (ListView) findViewById( R.id.shopList ); ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null); String[] from = { DB.column_name
ShopList = (ListView) findViewById( R.id.shopList );
ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null);
String[] from = { DB.column_name };
int[] to = { android.R.id.text1 };
shopAdapter = new SimpleCursorAdapter(
this, android.R.layout.simple_list_item_activated_1, c, from, to,
SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
ShopList.setAdapter(shopAdapter);
如何删除ListView中的项?我没有找到删除函数
ShopList = (ListView) findViewById( R.id.shopList );
ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null);
String[] from = { DB.column_name };
int[] to = { android.R.id.text1 };
shopAdapter = new SimpleCursorAdapter(
this, android.R.layout.simple_list_item_activated_1, c, from, to,
SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
ShopList.setAdapter(shopAdapter);
您不能从列表视图中删除项目。您可以修改或替换列表适配器
,使其不再具有该项。在您的情况下,由于您使用的是SimpleCursorAdapter
,因此需要:
- 从数据库中删除该项(在您的情况下,通过
ContentProvider
)
- 获取一个表示查询结果的新的
光标
- 调用
changeCursor()
(如果您使用的是Loader
框架)或swapCursor()
,将SimpleCursorAdapter
中的光标替换为新光标
由于您不应该在主应用程序线程上调用ContentResolver
上的query()
,因此您可能希望切换到CursorLoader
,在这种情况下,您可以在onLoadFinished()
中调用changeCursor()
如何删除ListView中的项?我没有找到删除函数
ShopList = (ListView) findViewById( R.id.shopList );
ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null);
String[] from = { DB.column_name };
int[] to = { android.R.id.text1 };
shopAdapter = new SimpleCursorAdapter(
this, android.R.layout.simple_list_item_activated_1, c, from, to,
SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
ShopList.setAdapter(shopAdapter);
您不能从列表视图中删除项目。您可以修改或替换列表适配器
,使其不再具有该项。在您的情况下,由于您使用的是SimpleCursorAdapter
,因此需要:
- 从数据库中删除该项(在您的情况下,通过
ContentProvider
)
- 获取一个表示查询结果的新的
光标
- 调用
changeCursor()
(如果您使用的是Loader
框架)或swapCursor()
,将SimpleCursorAdapter
中的光标替换为新光标
由于您不应该在主应用程序线程上调用ContentResolver
上的query()
,因此您可能希望切换到CursorLoader
,在这种情况下,您可以在onLoadFinished()
中调用changeCursor()
如何删除ListView中的项?我没有找到删除函数
ShopList = (ListView) findViewById( R.id.shopList );
ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null);
String[] from = { DB.column_name };
int[] to = { android.R.id.text1 };
shopAdapter = new SimpleCursorAdapter(
this, android.R.layout.simple_list_item_activated_1, c, from, to,
SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
ShopList.setAdapter(shopAdapter);
您不能从列表视图中删除项目。您可以修改或替换列表适配器
,使其不再具有该项。在您的情况下,由于您使用的是SimpleCursorAdapter
,因此需要:
- 从数据库中删除该项(在您的情况下,通过
ContentProvider
)
- 获取一个表示查询结果的新的
光标
- 调用
changeCursor()
(如果您使用的是Loader
框架)或swapCursor()
,将SimpleCursorAdapter
中的光标替换为新光标
由于您不应该在主应用程序线程上调用ContentResolver
上的query()
,因此您可能希望切换到CursorLoader
,在这种情况下,您可以在onLoadFinished()
中调用changeCursor()
如何删除ListView中的项?我没有找到删除函数
ShopList = (ListView) findViewById( R.id.shopList );
ShopList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Cursor c = getContentResolver().query(SHOP_LIST_URI, null, null, null, null);
String[] from = { DB.column_name };
int[] to = { android.R.id.text1 };
shopAdapter = new SimpleCursorAdapter(
this, android.R.layout.simple_list_item_activated_1, c, from, to,
SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
ShopList.setAdapter(shopAdapter);
您不能从列表视图中删除项目。您可以修改或替换列表适配器
,使其不再具有该项。在您的情况下,由于您使用的是SimpleCursorAdapter
,因此需要:
- 从数据库中删除该项(在您的情况下,通过
ContentProvider
)
- 获取一个表示查询结果的新的
光标
- 调用
changeCursor()
(如果您使用的是Loader
框架)或swapCursor()
,将SimpleCursorAdapter
中的光标替换为新光标
由于您不应该在主应用程序线程上调用ContentResolver
上的query()
,因此您可能希望切换到CursorLoader
,在这种情况下,您可以在onLoadFinished()
中调用changecoursor()
,首先从数据库中删除数据,然后添加数据
swapCursor(getContentResolver().query(SHOP_LIST_URI,null,null,null))
首先从数据库中删除数据,然后添加
swapCursor(getContentResolver().query(SHOP_LIST_URI,null,null,null))
首先从数据库中删除数据,然后添加
swapCursor(getContentResolver().query(SHOP_LIST_URI,null,null,null))
首先从数据库中删除数据,然后添加
swapCursor(getContentResolver().query(SHOP_LIST_URI,null,null,null))
AFIK,仅当从数据源中删除项目时,才能从列表视图中删除项目。AFIK,仅当从数据源中删除项目时,才能从列表视图中删除项目。AFIK,仅当从数据源中删除项目时,才能从列表视图中删除项目。AFIK,仅当从数据源中删除某项时,才能从listview中删除该项。