android网络编程之android连接网络的简单示例代码

时间:2021-05-20

复制代码 代码如下:
private void callToWebSrvice() {

ConnectivityManager connManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ) {
_progresssDialog = ProgressDialog.show(this,"Please Wait...","Retrieving Data");
getData();
} else
Toast.makeText(BestScore.this, "Network Error!!!", Toast.LENGTH_LONG).show();

}
public void getData(){

Thread _thread = new Thread(){

public void run(){

Message _msg = new Message();
_msg.what = _updataSmsLog;
callDataBase();
BestScore.this._uicallback.sendMessage(_msg);
}
};
_thread.start();
}

Handler _uicallback = new Handler(){

public void handleMessage(Message msg) {

switch(msg.what){

case _updataSmsLog :

if(_dataList.size() > 0 ){

_initial.setText(((Data)(_dataList.get(0)))._initial);
_wpm.setText(((Data)(_dataList.get(0)))._wpm);
_phone.setText(((Data)(_dataList.get(0)))._smartPhone);
_country.setText(((Data)(_dataList.get(0)))._country);

_progresssDialog.dismiss();
setListAdapter(new IconicAdator(BestScore.this,R.layout.viewrow,_dataList));
}
else{

_progresssDialog.dismiss();
Toast.makeText(BestScore.this,"No Record Found",Toast.LENGTH_LONG).show();
}
}

};

};

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章