我在一個活動中創建了一個對話框。使用異步任務,我會定期顯示該對話框。當我移動到另一個活動時是否可以顯示對話框?如何在多個活動中顯示相同的對話框?
1
A
回答
0
你可以製作一個按鈕來顯示對話框,在事件onclick顯示對話框的任何代碼,並設置按鈕點擊定期。
public void getRunningClick(){
new Handler().postDelayed(new Runnable() {
public void run() {
//your code showing dialog
}
},(2*1000));
}
希望對你的幫助
1
我做到了,在過去的2分不同的方式。
1)創建一個佈局,用作需要時顯示的對話框(導入到每個活動佈局中並隱藏)(也可以創建一個'空'活動,只彈出對話框並且如果需要該消息。 2)創建一個CustomDialog類並使用它(我用它來處理自定義字體,但是我只在這個代碼中放一次)。
//main Activity:
DialegError da = new DialegError(this);
da.crearDialeg("APP ERROR", "this is an error");
//Error class
public class DialegError {
private Activity a = null;
public DialegError(Activity activity){
a=activity;
}
/**
* Default NO-MESSAGE errorDialog
*/
public void crearDialeg(String titol){
AlertDialog dialog = new AlertDialog.Builder(a)
.setTitle(titol)
// .setIcon(R.drawable.)
.setPositiveButton(a.getString(R.string.button_aceptar), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.show();
}
/**
* Default errorDialog
*/
public void crearDialeg(String titol, String cos){
AlertDialog dialog = new AlertDialog.Builder(a)
.setTitle(titol)
.setMessage(cos)
// .setIcon(R.drawable.)
.setPositiveButton(a.getString(R.string.button_aceptar), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.show();
//Personalized font. No way to deal with the title text.
Typeface font=Typeface.createFromAsset(a.getAssets(),"fonts/font_name.ttf");
TextView textView = (TextView)dialog.findViewById(android.R.id.message);
textView.setTypeface(font);
textView = (TextView)dialog.findViewById(android.R.id.button1);
textView.setTypeface(font);
}
/**
* Error Dialog that closes the invoker activity.
*/
public void crearDialegError(String titol, String cos, int err){
final Activity activitat = a;
final int error = err;
AlertDialog dialog = new AlertDialog.Builder(activitat)
.setTitle(titol)
.setMessage(cos)
// .setIcon(R.drawable.)
.setPositiveButton(activitat.getString(R.string.button_aceptar), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
activitat.setResult(error, new Intent());
activitat.finish();
}
})
.show();
}
}
相關問題
- 1. 在同一個活動中顯示2個警報對話框
- 2. 如何在同一活動中處理多個對話框
- 3. 如何在另一個活動中顯示警報對話框?
- 4. 顯示一個對話框活動
- 5. 如何在活動中顯示對話框中的edittext輸入
- 6. 如何在android 4.4.2中顯示另一個對話框活動的對話框活動?
- 7. 如何在android中顯示asyntask的nonUI活動對話框?
- 8. 顯示2個不同的活動的對話框
- 9. 動態顯示活動爲對話框
- 10. 對話框顯示相同的結果
- 11. 如何在活動中顯示警報對話框?
- 12. 如何使用Phonegap在當前活動中顯示對話框
- 13. 在android中顯示另一個活動的對話框
- 14. 如何在不同情況下顯示相同的活動和片段中的對話框?
- 15. 使用活動顯示對話框?
- 16. 活動更改時顯示對話框
- 17. 在android中顯示一個活動作爲對話框
- 18. 想要在整個活動中顯示警報對話框
- 19. 如何在MFC中同時創建兩個活動對話框?
- 20. 如何在開始活動之前顯示進度對話框
- 21. android-如何在活動結束後顯示對話框
- 22. 如何在Android中顯示對話框中的對話框?
- 23. Android:在任何活動中顯示警報對話框
- 24. 如何顯示,從後臺活動啓動對話框
- 25. 如何在通話中顯示活動
- 26. 如何檢查是否顯示對話框或顯示同一類型的多個對話框?
- 27. 在對話框活動中自動顯示軟鍵盤
- 28. 如何顯示來自非活動類的警報對話框
- 29. 如何在jQuery Mobile中順序顯示多個對話框?
- 30. 在半透明的活動中顯示警告對話框
檢查這裏我的答案.... http://stackoverflow.com/questions/13561915/single-alert-dialog-for-entire-application/13561965# 13561965 –