我有这样的代码,但为什么我看不到progressdialog?
progress = ProgressDialog.show(MainActivity.this, "MOHON DITUNGGU", "Loading...", true);
String urlATM = "http://eplace.hol.es/android/OutputATM.php";
try {
JSONArray data = new JSONArray(getJSONUrl(urlATM));
if(data.length()!=0){
HashMap<String, String> map;
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("id_atm", c.getString("id_atm"));
map.put("id_bank", c.getString("id_bank"));
map.put("nama_bank", c.getString("nama_bank"));
map.put("latitude", c.getString("latitude"));
map.put("longitude", c.getString("longitude"));
map.put("name", c.getString("name"));
map.put("email", c.getString("email"));
MyArrListATM.add(map);
//end add marker
maps.addMarker(new MarkerOptions()
.title("ATM"+MyArrListATM.get(i).get("nama_bank"))
.snippet("24 Jam")
.position(new LatLng(
Double.parseDouble(MyArrListATM.get(i).get("latitude")),
Double.parseDouble(MyArrListATM.get(i).get("longitude")))));
}
progress.dismiss();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
progress.dismiss();
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("PERINGATAN");
alertDialog.setMessage("Error: "+e.getMessage());
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "TUTUP", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
我尝试删除一些代码,所以像这样的代码
progress = ProgressDialog.show(MainActivity.this, "MOHON DITUNGGU", "Loading...", true);
和progressdialog即将来临
那么如何使用上面的代码显示progressdialog?
答案 0 :(得分:1)
我想,简直没有错 您的循环执行发生得如此之快,以至于您的进度对话框甚至在您看到之前就被解除了
OR
您的try块中出现了一些异常,对话框在catch块
中被解除答案 1 :(得分:1)
一切都很好,你只需要在线程中添加一些延迟。
推荐:尝试使用AsyncTask进行此类工作。
progress = ProgressDialog.show(MainActivity.this, "MOHON DITUNGGU", "Loading...", true);
// Execute some code after 1 seconds have passed
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// YOur Request code here?
}
}, 1000);
答案 2 :(得分:0)
初始化进度对话框
ProgressDialog myProgressDialog = new ProgressDialog(this);
myProgressDialog.setIndeterminate(true);
myProgressDialog.setMessage("Loading...");
myProgressDialog.setCancelable(true);
并显示进度对话框
myProgressDialog.show();
解雇
myProgressDialog.dismiss();