gpt4 book ai didi

android - 为什么进度对话框无法显示?

转载 作者:搜寻专家 更新时间:2023-11-01 09:45:12 25 4
gpt4 key购买 nike

我有这样的代码,但为什么我看不到进度对话框?

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);

进度对话框即将显示

那么如何用我上面的一些代码显示进度对话框呢?

最佳答案

一切都很好,你只需要在线程中添加一些延迟。

推荐:尝试使用 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);

关于android - 为什么进度对话框无法显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38389396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com