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