我想显示警报对话框取决于属性,当用户点击确定按钮时,再次调用函数来获取运行过程中的更新值。如何在运行线程中显示警报对话框?
我有下面的代码: -
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