/ *我在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",int whichButton)
{
}
});
AlertDialog ad = alert.create();
ad.show();
}
//Thanks!
//ray.
最佳答案