我想关闭对话框后,用户单击对话框中驻留的ListView中的项目。这里是我的listDialog
方法被调用来打开对话框:关闭AlertDialog onItemClick后 - 自定义ListViewDialog
public void listDialog() {
LayoutInflater shoppingListInflater = LayoutInflater.from(this);
//volley request to get listview data
getListsRequest();
final View allListsView = shoppingListInflater.inflate(R.layout.list_picker_dialog, null);
listsPickerView = (ListView) allListsView.findViewById(R.id.shopping_lists_all);
shoppingLists = new ArrayList<ShoppingList>();
allListsAdapter = new ShoppingListsAdapter(this, shoppingLists);
listsPickerView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override public void onItemClick(AdapterView<?> arg0, View view, int arg2, long arg3) {
shopping_list_id = ((TextView) view.findViewById(R.id.list_id)).getText().toString();
JSONObject listItemData = new JSONObject();
try {
listItemData.put("inventory_item_id", inventory_item_id);
listItemData.put("shopping_list_id", shopping_list_id);
} catch (JSONException e) {
e.printStackTrace();
}
// a volley network call to an api
createListItemRequest(listItemData);
//where I want to close the dialog - after the network call. Not working currently
alertD.cancel();
}
});
listsPickerView.setAdapter(allListsAdapter);
AlertDialog.Builder listsDialog = new AlertDialog.Builder(this);
listsDialog.setView(allListsView);
listsDialog.setCancelable(false)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertD = listsDialog.create();
alertD.show();
}
除对话框取消之外的一切工作。由于alertD
不在ItemClickListener中,因此我无法引用它。网络通话后如何关闭此对话框 - 参考上面的内容?
用户.dismiss近距离dialoge –