单击项目时无法隐藏自定义对话框

时间:2015-06-29 03:25:37

标签: android dialog customdialog

这是我的对话onCreate

protected Dialog onCreateDialog(int id) {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.selection_item,null,false);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setContentView(view);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
    text_noteClick(view);
    checklist_noteClick(view);
    dialog.dismiss();
    return super.onCreateDialog(id);
} 

这是我的onClick事件

    public void checklist_noteClick(View v){
    Fragment fragment = null;
    fragment = new Text_Note_Fragment();
    FragmentManager frgManager = getSupportFragmentManager();
    frgManager.beginTransaction().replace(R.id.mainContent, fragment).addToBackStack("gg")
            .commit();
}
public void text_noteClick(View v){
    Fragment fragment = null;
    fragment = new Text_Note_Fragment();
    FragmentManager frgManager = getSupportFragmentManager();
    frgManager.beginTransaction().replace(R.id.mainContent, fragment).addToBackStack("gg")
            .commit();

    removeDialog(getTaskId());
}

我希望对话框关闭或隐藏此onClick函数中的事件。

1 个答案:

答案 0 :(得分:0)

我认为您从xml设置了onClick侦听器。试试这个。

ListView lv = (ListView)dialog.findViewById(R.id.your_listview_id);
lv.setOnClickListener(new View.onClickListener(){
 @Override
 public void onClick(View v){
//your codes
dialog.dismiss();
}
});

希望这会有所帮助。 :)