![](/img/trans.png)
[英]How can I use a Variable from a Class Runner to use in a Method in another Class? (BlueJ, Java)
[英]How to use a variable from method in another class?
我的警报对话框有一些问题...如何调用alert.show(); 在第二类中调用警报对话框?
我需要显示alertdialog onReceive方法,但我不能这样做...
有人可以帮我吗?
ps对不起,我的英语。
主类:
public class Main extends Activity {
...
public void onTimeSet(TimePicker view, int hour, int minute) {
...
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("ALARM");
builder.setMessage("Wstajesz czy dalej drzemiesz ?!");
builder.setPositiveButton("Wstaje...", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do do my action here
dialog.dismiss();
}
});
builder.setNegativeButton("Spie!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// I do not need any action here you might
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
....
}
二等舱:
public class Second extends BroadcastReceiver {
@Override
public void onReceive(Context k1, Intent k2) {
/*
--> here i want to call an alert using: alert.show(); It's possible ?
*/
}
}
您无法显示来自Receiver
的Dialog
,需要Activity
。 可以使用Intent
启动MainActivity
也可以根据自己的实际需要将其设置为带有Dialog theme
的单独Activity
。 您可以通过创建一个Activity
并在manifest
使用主题进行声明来实现此目的
android:theme="@android:style/Theme.Dialog"
请注意,从Receiver
创建Intent
以启动Activity
时,需要设置Intent.FLAG_ACTIVITY_NEW_TASK
标志
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.