/*我遇到了一个奇怪的问题,在OnMenuItemClickListener内,我调用了一个自己制作的警告对话框,但是似乎当我调用警告对话框时,并没有在正确的时刻显示出来,而是在onMenuItemClick完成之后才显示。我做错了什么?*/
class MyListMenuListener implements OnMenuItemClickListener
{
private String TAG;
@Override
public boolean onMenuItemClick(MenuItem item)
{
if (item.getItemId() == saveRoute.getItemId())
{
alertDialogSaveFile();
//nameInput = "testone.txt";
//some operations
// ...
// return true;
}
// ...
/*the wierd thing is that the alert dialog doesnt show up on the same moment i call it..
only after the onMenuItemClick operation ends (with return)
and this is how my alertdialog looks like:*/
private void alertDialogSaveFile()
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Save your current map");
alert.setMessage("Please insert name for this route");
final EditText saveNameInput = new EditText(TwittListActivity.this);
alert.setView(saveNameInput);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
nameInput = saveNameInput.getText().toString();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
});
AlertDialog ad = alert.create();
ad.show();
}
//Thanks!
//ray.