Android的警告对话框,并设置正按钮 [英] Android alert dialog and set positive button
本文介绍了Android的警告对话框,并设置正按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个拼图。我想用OK按钮显示一个对话框,当拼图完成。当OK按钮是pressed,我使用意图
加载通过Android浏览网站。唯一的问题是,在当前code,当拼图完成后,它不会加载一个盒子(它当我使用空
)。它没有做任何事情。任何想法?
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(puzzle.isSolved()R.string.title_stats:stats.isNewBest()R.string.title_new_record:??R.string.title_solved);
builder.setMessage(MSG);
builder.setPositiveButton(R.string.label_ok,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话框,INT ID){
意向意图=新的意图(android.intent.action.VIEW,Uri.parse(HTTP://www..com));
叠B =新包();
b.putBoolean(new_window,真正的); //设置新窗口
intent.putExtras(B);
startActivity(意向);
}
});
解决方案
AlertDialog.Builder建设者=新AlertDialog.Builder(your_activity.this);
builder.setTitle(puzzle.isSolved()R.string.title_stats:stats.isNewBest()R.string.title_new_record:??R.string.title_solved);
builder.setMessage(MSG);
builder.setPositiveButton(R.string.label_ok,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话框,INT ID){
意向意图=新的意图(android.intent.action.VIEW,Uri.parse(HTTP://www..com));
叠B =新包();
b.putBoolean(new_window,真正的); //设置新窗口
intent.putExtras(B);
startActivity(意向);
}
});
builder.show();
试试这个
This is for a slider puzzle. I want to show a dialog box with OK button when the puzzle is completed. When the OK button is pressed, I use an Intent
to load a website via Android browser. Only problem is that with the current code, when the puzzle is complete, it does not load a box (it does when I use null
). It doesn't do anything. Any ideas?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(!puzzle.isSolved() ? R.string.title_stats : stats.isNewBest() ? R.string.title_new_record : R.string.title_solved);
builder.setMessage(msg);
builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www..com"));
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
intent.putExtras(b);
startActivity(intent);
}
});
解决方案
AlertDialog.Builder builder = new AlertDialog.Builder(your_activity.this);
builder.setTitle(!puzzle.isSolved() ? R.string.title_stats : stats.isNewBest() ? R.string.title_new_record : R.string.title_solved);
builder.setMessage(msg);
builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www..com"));
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
intent.putExtras(b);
startActivity(intent);
}
});
builder.show();
try this
这篇关于Android的警告对话框,并设置正按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文