1
我試圖通過創建一系列可以在Android中執行的對話框菜單來模擬Android中的USSD交互。我試圖讓它在對話框之間有一個表示「USSD代碼正在運行...」的進度對話框。但是,當點擊肯定按鈕時,當我嘗試使用可運行定時器運行ProgressDialog並按照它進行操作時通過下一個名爲FirstTimeUser的對話框,即使我嘗試將它們與另一個計時器分開,它們也會將一個層疊到另一個上面。我如何讓它們連續運行而不是同時運行?下面的代碼片段:在對話框之間顯示ProgressDialog
USSDprogressDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
final View dialogView = inflater.inflate(R.layout.number_response_dialog, null);
builder.setView(dialogView)
.setMessage(R.string.MainMenuText)
// Add action buttons
.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Send number to next dialog
String choice = getMenuChoice(dialogView);
if (choice.equals("5")) {
USSDprogressDialog();
FirstTimeUse();
} else {
//Do nothing
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// End session
}
});
AlertDialog dialog = builder.create();
dialog.show();
與進步具有定時對話框:
public void USSDprogressDialog() {
final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("USSD code running...");
progress.show();
Runnable progressRunnable = new Runnable() {
@Override
public void run() {
progress.cancel();
}
};
Handler handler = new Handler();
handler.postDelayed(progressRunnable, 2000);
}
任何建議將受到歡迎!謝謝!
我試圖包括FirstTimeUse progresscancel,如你所建議的那樣,工作!但是現在我又遇到了另一個問題,那就是我需要製作USSDProgressDialog泛型,以便能夠將它包含在所有對話框之間,並且我有很多對話框。不過,我會繼續努力。謝謝!! – notchopra
看看第二句 - 讓USSDprogressDialog收到一個可運行的 –
啊!我明白你的意思了。謝謝!! – notchopra