I have Created a dialogue using android.support.v7.app.alertdialog class. here is my code
final AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this,R.style.AppCompatAlertDialogStyle);
myAlertDialog.setTitle("Enter Text");
final EditText input = new EditText(MainActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
myAlertDialog.setView(input);
myAlertDialog.setCancelable(false);
myAlertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
if (input.getText().toString().length() != 0) {
myAlertDialog.setCancelable(true);
startActivity(new Intent(MainActivity.this,SelectCatDialogue.class).putExtra("text",input.getText().toString()));
} else {
myAlertDialog.setCancelable(false);
Toast.makeText(getApplicationContext(),"Please Enter Text",Toast.LENGTH_SHORT).show();
}
}
});
myAlertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
myAlertDialog.setCancelable(true);
}
});
myAlertDialog.show();
now this dialog auto cancelled when i click on either positive or negative button but i need it should only cancelled on negative button not on positive button