我想顯示警報對話框取決於屬性,當用戶點擊確定按鈕時,再次調用函數來獲取運行過程中的更新值。如何在運行線程中顯示警報對話框?
我有下面的代碼: -
importingProgress = ProgressDialog.show(context, getString(R.string.progressNewsListTitle),
getString(R.string.progressProjectListMessage), true);
new Thread(new Runnable() {
public void run() {
try
{
app.SetOtherTaskRunning(true);
Ib_clients client = db.Ib_clients_GetById(app.GetCustomerId());
try {
LogManager.WriteToFile("---------------- Getting News from Webservice :- "+DateFormat.getDateTimeInstance().format(new Date())+"----------------");
CommonFuctions.CreateXml(context,h,client,db,app.GetBookMonth(),app.GetBookQuater(),app.GetBookYear(),Constants.News,app.GetWebServiceLastSyncDate(Constants.ServiceType.NEWS.toString()),Constants.ServiceType.NEWS,null,null,null,null,null);
Return reponse=null;
do
{
reponse=CommonFuctions.SendingRequest(context, handler, db);
if(reponse.type.compareTo("warning")==0)
{
h.post(new Runnable() {
public void run() {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(context.getString(R.string.information));
alert.setMessage("dsgdgd");
alert.setPositiveButton(context.getString(R.string.logoutDialogOk), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
});
}
}while(reponse.type.compareTo("warning")==0);
} catch (IOException e) {
e.printStackTrace();
}
}
catch (Exception e) {
//Log.d(Constants.TAG, e.getMessage());
e.printStackTrace();
}
if (importingProgress != null)
{
importingProgress.dismiss();
importingProgress=null;
}
}
}).start();
如果響應類型是警告,然後顯示給用戶的消息,當點擊OK按鈕,然後再次調用CommonFuctions.SendingRequest(背景下,處理程序,DB),以獲得更新的值。直到我們得到的響應類型是警告,我們需要向用戶顯示警告對話框,並再次調用CommonFuctions.SendingRequest(context,handler,db)。
返回分類: -
public class Return {
public String type;
public String msg;
public boolean isSuccess;
public int client_id; // for getting clientid from server
public int booking_id; // for getting bookingid form server
}
把你alertdialog代碼獨立於主線程。嘗試在runonUIThread上運行它。 – GrIsHu
你可以通過使用處理程序和它的post方法來做到這一點,因爲它必須在UI線程上運行 – techieWings