程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-當我點擊ListView item時如何關閉AlertDialog?

android-當我點擊ListView item時如何關閉AlertDialog?

編輯:編程綜合問答
當我點擊ListView item時如何關閉AlertDialog?

下面是 dialog 代碼,在 dialog 中有一個 ListView,我想在點擊 ListView item 時關閉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();     
    }

我想在onItemClick()方法中加入代碼

但是不能執行。
怎麼處理?

最佳回答:


private void windowDialog(){
      Window mWindow = newDialogView();
      mWindow.setContentView(R.layout.kl_dialog_invite_code);
      ListView listview=mWindow.findViewById(R.id.xxx);
      //在onItemClick事件中調用mDialog.dismiss();就ok了
}

private Window newDialogView() {
        if (mDialog == null) {
            mDialog = new Dialog(this, R.style.mydialog);
            mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
        mDialog.show();
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        Window win = mDialog.getWindow();
        WindowManager.LayoutParams lp = win.getAttributes();
        // lp.alpha = 0.9f;
        win.setAttributes(lp);
        // WindowManager.LayoutParams.FLAG_DIM_BEHIND 背景漸變
        // WindowManager.LayoutParams.FLAG_BLUR_BEHIND 背景模糊
        win.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        return win;
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved