Android线程中使用Toast、dialog、loading
代码改变世界
Android线程中使用Toast、dialog、loading
Loading:
Thread t1 = new Thread(new Runnable() { @Override public void run() { Looper.prepare(); LoadingUnit.showLoading(context);
if (!result.isEmpty()) { JSONObject paramJson = JSON.parseObject(result); String resultFlag = paramJson.getString("result_flag"); resultId = paramJson.getString("yw_user_id"); versionValue = paramJson.getString("app_version"); versionUrlValue = paramJson.getString("app_download_url"); if ("1".equals(resultFlag)) { loginReturnValue = "1"; LoadingUnit.cancel(); }else if ("2".equals(resultFlag)) { loginReturnValue = "2"; LoadingUnit.cancel(); }else if ("3".equals(resultFlag)) { loginReturnValue = "3"; LoadingUnit.cancel(); }else{ loginReturnValue = "4"; LoadingUnit.cancel(); } }
} });
Toast:
private Handler handlerSuccess = new Handler() { @Override public void handleMessage(Message msg) { Toast.makeText(CommodityDetails.this, "修改成功!", Toast.LENGTH_SHORT).show(); } };
使用:
handlerSuccess.sendEmptyMessage(0);
Dialog同上
期待美好!
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
LoadingUnit.showLoading(context);
JSONObject jsonObject = new JSONObject();
String json = "";
try {
jsonObject.put("yw_user_phone", showName);
jsonObject.put("yw_user_password", showPaw);
json = JSONObject.toJSONString(jsonObject);//参数拼接成的String型json
json = URLEncoder.encode(json, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
String result = CallAPIUtil.ObtainFun(json, Common.loginUrl);
if (!result.isEmpty()) {
JSONObject paramJson = JSON.parseObject(result);
String resultFlag = paramJson.getString("result_flag");
resultId = paramJson.getString("yw_user_id");
versionValue = paramJson.getString("app_version");
versionUrlValue = paramJson.getString("app_download_url");
if ("1".equals(resultFlag)) {
loginReturnValue = "1";
LoadingUnit.cancel();
}else if ("2".equals(resultFlag)) {
loginReturnValue = "2";
LoadingUnit.cancel();
}else if ("3".equals(resultFlag)) {
loginReturnValue = "3";
LoadingUnit.cancel();
}else{
loginReturnValue = "4";
LoadingUnit.cancel();
}
}
}
});