我有按鈕,用戶選擇,我彈出一個AlertDialog OK或取消操作取代一些數據。我想出了它的一個ASYNCH過程後,OK和CANCEL工作正常。 我甚至停止多次點擊。但是,當用戶按下「確定」時,我必須將這些信息與一些任務一起保存到內存中。 OK過程大約需要三秒鐘,這是不耐煩的人的邊緣。我想用消息拋出一個不確定的進度條。然而,我對Java和android的新鮮感正在阻礙之中。 下面代碼中的「上下文」究竟是什麼?ProgressDialog麻煩
public void getData(final View v)
{
if(AlertDialogProcessing==0)
{
final String title="Set Image to Wallpaper";
final String message="Press OK to set as Wallpaper or CANCEL";
final String ok="OK";
final String cancel="CANCEL";
final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
try{
alertbox.setMessage(message);
alertbox.setTitle(title);
alertbox.setPositiveButton(ok,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1)
{
Vibrate(ClickVibrate);
Drawable drawable= getSun(imageSelect);
ProgressDialog dialog = ProgressDialog.show(context, "Loading", "Please wait...", true); //<<<<<<<<<<ERROR at context
AlertDialogProcessing=1;
SaveData(drawable,1);
AlertDialogProcessing=0;
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Data Saved.",Toast.LENGTH_LONG).show();
}
});
alertbox.setNegativeButton(cancel,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1){
AlertDialogProcessing=0;
Vibrate(ClickVibrate);
}
});
//alertbox.setCanceledOnTouchOutside(false); // maybe a 4.0 problem
alertbox.show();
} catch(Exception e){
//TODO Handle BadTokenException.
}
}
}
似乎Android需要一個允許程序員口授的管理程序 – user1445716
似乎Android需要一個允許程序員有時口述命令的管理程序。我已經完成了並行和線程編程,異步似乎是兩者的結合,也是兩者的頭痛。事實證明,我以3秒的懲罰保存數據的擔憂並沒有被我交給pgm的隨機人員注意到。我將不得不添加異步到我的工具箱下載文件。實際上,我發現google android exampleless引用沒有什麼幫助。感謝這裏的努力。 – user1445716