[英]how do you add an item in a list if a user presses yes button in an alert dialog box and don't add it if he presses no
I am making an app in which if a user selects a submenu item I pop up an Alert dialog which asks his confirmation whether he wishes to save that item in his list and saves it if he presses yes and doesn't add it if he presses no.我正在制作一个应用程序,如果用户选择一个子菜单项,我会弹出一个警报对话框,询问他是否希望将该项目保存在他的列表中,如果他按下是则保存它,如果他按下则不添加它不。
You can use this to show alert:您可以使用它来显示警报:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure to do this?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
doSomeThing();
dialog.cancel();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
You add the element you get from the dialog to the ArrayList you use to feed your Adapter
then feed the cursor = new yourAdapter(YourClass.this.getBaseContext(), android.R.layout.simple_list_item_1, dataList);
You add the element you get from the dialog to the ArrayList you use to feed your
Adapter
then feed the cursor = new yourAdapter(YourClass.this.getBaseContext(), android.R.layout.simple_list_item_1, dataList);
Call cursor.notifyDataSetChanged();
调用
cursor.notifyDataSetChanged();
which tells the list to repopulate with the new data;它告诉列表重新填充新数据;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.