在 if 条件下不会关闭对话框

Dialog not dismiss in if condition

我试图关闭 if condition true 部分的对话框,但它不起作用。 在对话框中输入 if 条件但不是 dismiss.in 如果条件 toast 消息显示正确。

public void showIncomingCall() {

        int getTotal = 0;

        if(showincoming != null && showincoming.isShowing() )
        {
            //adapter1.notifyDataSetChanged();
            //showincoming.dismiss();
            return;
        }
        else {
            showincoming = new Dialog(MainActivity.this);
            showincoming.requestWindowFeature(Window.FEATURE_NO_TITLE);
            showincoming.setContentView(R.layout.custome_dialog);
            listdialog = (ListView) showincoming.findViewById(R.id.incoming_list);
            //adapter1 = new CustomeListAdapter(MainActivity.this);
            listdialog.setAdapter(adapter1);
            //adapter1.notifyDataSetChanged();
             close = (ImageButton) showincoming.findViewById(R.id.dialog_close);

            close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    showincoming.dismiss();
                    adapter1.notifyDataSetChanged();
                }
            });

            adapter1.notifyDataSetChanged();

            for (int i = 0; i < listdialog.getCount(); i++) {
                parentView = getViewByPosition(i, listdialog);
                String getString = ((TextView) parentView.findViewById(R.id.tvLineStatus)).getText().toString();

                if (getString.toString().equals("Idle") || getString.toString().equals("Disconnect") || getString.toString().equals("Dialing")) {
                    getTotal += 1;
                }
            }
            if (getTotal >= 7) {
                    showincoming.dismiss();
                    Toast.makeText(getApplicationContext(),"getTotal" + getTotal,Toast.LENGTH_LONG).show();
                    adapter1.notifyDataSetChanged();

                //adapter1.setNotifyOnChange(true);
            }
            //Toast.makeText(MainActivity.this,getTotal+"getTotal",Toast.LENGTH_LONG).show();
            adapter1.notifyDataSetChanged();
            listdialog.invalidateViews();
            if(!showincoming.isShowing()) {
                showincoming.show();
            }
        }
}

showincoming = new Dialog(MainActivity.this);int getTotal = 0; 下面声明,即在 else 声明之外 然后您可以获得对话框对象的引用并可以关闭对话框。试试这个,让我知道