1

我已将 ListView 放入 AlertDialog 中,并且我想在单击 ListView 项目时关闭 AlertDialog;我该怎么做?

public void createSearchDialog(final String[] Memo){
    LayoutInflater factory = LayoutInflater.from(this);
    View searchView = factory.inflate(R.layout.seach_dialog, null);

    lv = (ListView) searchView.findViewById(R.id.search_list);
    lv.setAdapter(new MyPerformanceArrayAdapter(this, Memo, memo_PW));
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) {
            // TODO Auto-generated method stub

                     /// close dialog
        }
    });

    searchBuilder = new AlertDialog.Builder(this);
    searchBuilder.setTitle("Search")
           .setView(searchView)
           .setNegativeButton("Back", new DialogInterface.OnClickListener() {               
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub

            }
        })
           .show();     
}
4

2 回答 2

1

只需像这样抓住指向警报对话框的指针

AlertDialog myDialog = searchBuilder.setTitle("Search")
           .setView(searchView)
           .setNegativeButton("Back", new DialogInterface.OnClickListener() {               
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub

            }
        }).create();

然后稍后您可以通过致电解雇

myDialog.dismiss() 
于 2012-04-23T13:33:38.303 回答
1

通过使用应用程序上下文,您可以通过调用 dimiss 来关闭它。

Application.getProgressDialog().dismiss();

这必须在列表视图中处理onItemClick()

于 2012-04-23T12:51:22.027 回答