我正在为我的应用程序使用 Web 服务。方法 callWebService() 中的数据正在增加。我在填充我的 ListView 时显示 ProgressDialog。我还想检查是否没有网络连接来关闭 ProgressDialog 并显示 AlertDialog用户。有人可以帮我吗这是我的代码
myProgressDialog = ProgressDialog.show(ExchangeMoneMK1Activity.this,
"Please wait...", "Loading...", true);
Thread thread = new Thread(this);
thread.start();
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case 0:
myProgressDialog.dismiss();
int resID = R.layout.list_item;
aa = new ExchangeRateAdapter(ExchangeMoneMK1Activity.this, resID,currencyList);
lw.setAdapter(aa);
break;
}
}
};
public void run() {
// TODO Auto-generated method stub
try {
if(isNetworkAvailable())
callWebService();
handler.sendEmptyMessage(0);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我还没有警报对话框,因为如果没有互联网连接,进度条不会消失,我已经放入了 AndroidManifest 权限
有人可以帮我吗?