如何在列表适配器上删除项目后刷新片段列表?
这是我的适配器代码: https://pastebin.com/rGhV3fXj
builder.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if(pos!=1){
sqLiteDatabase.execSQL("DELETE FROM BmiPersons where id = "+pos );
Toast.makeText(getContext(),"Delete Success !",Toast.LENGTH_SHORT).show(); ListDataAdapter.this.notifyDataSetChanged();
}else {
Toast.makeText(getContext(),"You Can't delete initial data. ",Toast.LENGTH_SHORT).show();
}
这是我的片段代码: https://pastebin.com/hcPDKtVA
public void updatePersonList(){
mBmiList.clear();
dbHelper = new DatabaseHelper(getContext());
sqLiteDatabase = dbHelper.getReadableDatabase();
cursor = dbHelper.getBmiInformation();
if (cursor.moveToFirst()){
do{
list_id = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.COLUMN_ID));
list_date = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_DATE));
list_age = cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_AGE));
list_result = Float.parseFloat(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_RESULT)));
DataProvider dataProvider = new DataProvider(list_id,list_date,list_age,list_result);
mBmiList.add(dataProvider);
}while (cursor.moveToNext());
}
mListDataAdapter.notifyDataSetChanged();
}
答案 0 :(得分:0)
您必须删除mBmiList
中使用的mListDataAdapter
数据,然后调用mListDataAdapter.notifyDataSetChanged();