I have a dialog in an Android app that I don't want the user to be able to cancel. Using .setCancelable(false)
disables the back button, but pressing the search button still cancels the dialog. I saw this question which told me that I should include
public boolean onSearchRequested() {
return false;
}
But I'm still able to cancel the dialog with the search button. Here's my code:
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showDialog(0);
}
public boolean onSearchRequested() {
return false;
}
protected Dialog onCreateDialog(int id) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Message")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// nothing
}
});
return builder.create();
}
}