0
我打电话给我的ArrayAdapter
从Activity
,它显示了我的数据库中的数据集列表。如果用户点击ArrayAdapter
的项目,它将打开AlertDialog
的扩展。如果用户点击此AlertDialog
中的按钮,数据库中的数据集将被删除,其中AlertDialog
为dismiss()
。现在我想刷新ArrayAdapter
的视图。刷新从ArrayAdapter的AlertDialog后的活动
我发现像
remove(position);
notifyDataSetChanged();
但我在哪里可以把这个解决方案?如果用户点击特定按钮来说“hey adapter,请删除列表中的当前项目”,我可以将AlertDialog
的布尔值向后传递给ArrayAdapter
吗?
这里的一些代码:
活动:
final ListView list = (ListView) findViewById(R.id.myList);
DBhandler db = new DBhandler (context);
list.setAdapter(new MyAdapter(context, db.getMyItems()))
MyAdapter:
public View getView(int position, View row, ViewGroup parent) {
if(row != null) {
row.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final MyDialog myDialog = new MyDialog(context, currentItem);
myDialog.show();
}
});
}
}
MyDialog:
protected void onCreate(Bundle savedInstanceState) {
Button btn_delete = (Button) findViewById(R.id.btn_delete);
btn_delete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DBhandler db = new DBhandler (context);
db.delete(currentItem);
Toast.makeText(context, "item is deleted", Toast.LENGTH_SHORT).show();
dismiss();
}
});
}
我还发现Passing Events Back to the Dialog's Host,但我不“知道我该如何使用,对于我的AlertDialog ...
遗憾的功能之前,我不明白...我应该在哪里调用这些方法? AlertDialog中没有适配器实例,是吗? – lis