我创建了一个Listview,它从SQLite数据库中填充,而Long Click,在ListView Item I上提供了一个带有两个Button Delete和Cancel的DialogBox。单击删除按钮我想从SQLite Database中删除该ListView项。但是我没有在数据库中添加任何主键。那么如何通过项目位置删除它。
答案 0 :(得分:3)
ArrayList<Object> items = query from sqlite; <--- notice
then set items to listView adapter
enter code here
在onitem中单击
@Override
public void onItemClick(final AdapterView<?> parent, View arg1, final int **position**, long arg3)
{
....
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Integer deleteItem=
databaseHelper.delete_byID
(items.get(**position**).primaryKey); <----- change this
if(deleteItem>0)
Toast.makeText(getContext(), "Successfully Deleted", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getContext(), "Not", Toast.LENGTH_SHORT).show();
}
});
builder.show();][1]
并重新加载Listview以将其从listView中删除;
答案 1 :(得分:0)
您可以在文字视图中以可见性View.GONE