如何显示在窗口小部件的对话? [英] How to show a dialog on a widget?
问题描述
我想显示一个对话框,当我使用的ShowDialog(...)上的活动类的,但我需要做一个小部件,所以我不能使用的ShowDialog(...)。我怎样才能做到这一点?
i'd like to show a dialog, like when i use showDialog(...) on the Activity, but i need to do that on a widget, so i can't use showDialog(...). How can i do that?
我想这对我的onReceive方法,但它崩溃:
I tried this on my onReceive method but it crash:
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(context);
builder.setMessage("Are you sure?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
db.open();
db.remove_last();
db.close();
dialog.dismiss();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
谢谢,瓦莱里奥
Thanks, Valerio
推荐答案
Widget是不是要支持那种互动的,并且由于它们的启动程序的UID,而不是你的应用程序中运行,他们不是将不得不对数据库的访问。 (这可能是你崩溃的原因。看日志,找出肯定的)
Widgets aren't intended to support that kind of interaction, and since they run under the UID of your launcher and not that of your application, they're not going to have access to the database. (That's probably the cause of your crash; look in the log to find out for sure.)
启动应用程序中的一个活动,你想要做什么。如果你希望它看起来像一个对话框,应用 Theme.Dialog
风格:
Launch an activity in your application that does what you want. If you want it to look like a dialog box, apply the Theme.Dialog
style:
<activity
android:name=".MyThing"
android:label="@string/mythinglabel"
android:theme="@android:style/Theme.Dialog"
/>
这篇关于如何显示在窗口小部件的对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!