Answer the question
In order to leave comments, you need to log in
AlertDialog works only the second time, why?
Hello, the problem is this:
I have a button in a menu item, after pressing which an AlertDialog should open. But on the first click on the button, nothing happens (AlertDialog does not fire), AlertDialog only fires on the second click on the button.
What could it be? I am attaching below the code for handling this button from the menu item:
public void settingCount(MenuItem item) {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.setting_dialog, null);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setView(view);
final EditText editTextString = (EditText) view.findViewById(R.id.editTextDialogString};
dialogBuilder
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
///.....///
})
.setNegativeButton("Отмена",
new DialogInterface.OnClickListener(){
///.....////
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return true;
}
});
}
Answer the question
In order to leave comments, you need to log in
In a comment, you showed how the settingCount method is called :
<item
...
android:onClick="settingCount" />
public void settingCount(MenuItem item) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.setting_dialog, null);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setView(view);
final EditText editTextString = (EditText) view.findViewById(R.id.editTextDialogString};
dialogBuilder
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
///.....///
})
.setNegativeButton("Отмена",
new DialogInterface.OnClickListener(){
///.....////
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question