0

I have extended a DialogFragment. It just has an EditText and Accept and Cancel buttons.

Inside it, a text is entered to an EditText; then, upon clicking Accept, the text is checked using try/catch.

Inside the try, if everything goes fine, I dismiss the dialog; if the flow enters the catch, the idea is to retain the dialog and not dismiss it, to give the user the chance to correct the text.

@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
    }
}

However, the dialog is still being dismissed although I am not calling this.dismiss() inside the catch.

Is there any way to cancel the dismissal once inside onAcceptDialog()?

Jago
  • 2,751
  • 4
  • 27
  • 41

1 Answers1

0

I got the same issue make a custom dialog to solve this problem.

@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();      
} 
}

For your reference.. Hope this will help you.

Community
  • 1
  • 1
Nirmal
  • 2,340
  • 21
  • 43
  • I guessed this would be the only choice, but I didn't want to loose the semantics of the Ok and Cancel button... thanks anyway! – Jago Jun 21 '13 at 11:13