Sql:
sqLiteDatabase.execSQL("create table User( _id integer primary key autoincrement , name text , pass text )");
main
//长按点击事件
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, final int argindex, long l) {
index =argindex;
Log.d("tttt", index+"");
AlertDialog.Builder builder = new AlertDialog.Builder(Forgot.this);
builder.setMessage("你确定要删除这个账号吗?");
builder.setTitle("提示");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
list.remove(argindex);
SQLiteDatabase database =sql.getWritableDatabase();
database.delete("User","_id=?",new String[]{(Integer.toString(index))});
// database.delete(this."id=?",new String[]}{Integer.toString(index)});
adapter.notifyDataSetChanged();
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
}
});
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
return false;
}
});