Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击“确定”按钮后取消关闭对话框片段_Android_Android Dialogfragment - Fatal编程技术网

Android 单击“确定”按钮后取消关闭对话框片段

Android 单击“确定”按钮后取消关闭对话框片段,android,android-dialogfragment,Android,Android Dialogfragment,我扩展了一个对话框片段。它只有一个EditText和接受和取消按钮 在它里面,一个文本被输入到一个EditText;然后,单击“接受”后,使用try/catch检查文本 在try中,如果一切顺利,我会关闭对话框;如果流进入捕获,则想法是保留对话框,而不是关闭它,以便用户有机会更正文本 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ... builder.setPositiveButton(a

我扩展了一个
对话框片段
。它只有一个
EditText
和接受和取消按钮

在它里面,一个文本被输入到一个
EditText
;然后,单击“接受”后,使用
try/catch
检查文本

try
中,如果一切顺利,我会关闭对话框;如果流进入
捕获
,则想法是保留对话框,而不是关闭它,以便用户有机会更正文本

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ...
    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            onAcceptDialog();
        }
    })
    ...
}

...

private void onAcceptDialog() {
    try {
        ...
        this.dismiss();
    } catch (Exception e) {
        ...
        //Dialog is still being dismissed here although it shouldn't
    }
}
但是,尽管我没有在
catch
中调用
this.dislose()
,该对话框仍被取消


在AcceptDialog()中有没有取消解雇的方法?

我也遇到同样的问题,制作一个自定义对话框来解决这个问题

@Override
protected Dialog onCreateDialog(int id)
{

final AlertDialog.Builder alert = new AlertDialog.Builder(this);    
alert.setTitle("Test");
alert.setIcon(R.drawable.logo1);
alert.setMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus.");
 LinearLayout lila1= new LinearLayout(this);
LinearLayout linbuttons = new LinearLayout(this);
linbuttons.setOrientation(LinearLayout.HORIZONTAL);
Button btnPositive = new Button(this);
Button btnNegative = new Button(this);
btnPositive.setText("Send");
btnPositive.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // write your code for sending
        onBackPressed();
    }
});
btnNegative.setText("Cancel");
btnNegative.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        onBackPressed();
    }
});
linbuttons.addView(btnPositive);
linbuttons.addView(btnNegative);
lila1.addView(linbuttons);

return alert.create();      
} 
}

为了你的健康。希望这能对您有所帮助。

我猜这是唯一的选择,但我不想失去“确定”和“取消”按钮的语义。。。无论如何谢谢你!