[英]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.