寫這個函數來創建警告框
public static void MyAlertBox(String title, String mymessage, Context context)
{
new AlertDialog.Builder(context)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
.
}
})
.show();
}
聲明全局veriable:
public static Activity currentActivity= null;
在每個活動: 的onResume()寫「currentActivity =這一點; 「如果你想顯示警報
只寫:(活動1)
SplashScreen.MyAlertBox("Alert",
"Alert box from activity 1",currentActivity);
希望它會爲你工作!