警告框在Android中并不让我点击,只需直接执行操作 [英] Alert Box in Android doesn't let me to click, just directly performs the action
问题描述
我在单击应显示只包含确定按钮的alertdialog框,点击后,应该到另一个活动已经一个按钮。但是,此对话框中会出现几秒钟,然后进到活动而不让我点击或确认。这是code我用
I've a button upon clicking should display an alertdialog box containing just "OK" button and upon clicking should go to another activity. But this dialog box appears for a few seconds and goes to the activity without letting me click or confirm it. This is the code i've used
public void onClick(View v) {
AlertDialog.Builder alertbox = new AlertDialog.Builder(InsertData.this);
alertbox.setMessage("Object Location Stored!");
alertbox.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Intent a = new Intent(getApplicationContext(),MainMenu.class);
startActivity(a);
}
});
alertbox.show();
}
任何人都可以请帮我解决这个?由于在副词。
Can anyone pls help me resolve this? Thanks in adv..
推荐答案
我看不出有什么问题。前几天,我想包括AlertDialog自己。我看到有很多的德precated方法。最后我用下面的code。试试这个,如果你喜欢
I don't see what the problem is. A few days ago, I tried to include an AlertDialog myself. I saw that there are a lot of deprecated methods. I ended up using the code below. Try this if you like
AlertDialog ad=new AlertDialog.Builder(this).create();
ad.setTitle(R.string.app_name);
ad.setMessage("MESSAGE");
ad.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}});
ad.show();
这篇关于警告框在Android中并不让我点击,只需直接执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!