<分区>
这是我的布局代码;
private class mainAdapter extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
@Override
protected void onPostExecute(String result) {
if(flagsearch)
{
pd.dismiss();
if(result.trim().contains("Result not found !"))
{
Toast.makeText(getApplicationContext(), result.trim(), Toast.LENGTH_LONG).show();
}
else
{
String limit=""+0;
Intent i= new Intent(Main_Search.this,Main_listview.class);
i.putExtra("line", result);
i.putExtra("limit",0);
i.putExtra("Alert", false);
i.putExtra("str_Descrption",str_desc);
i.putExtra("str_location", str_location);
startActivity(i);
}
//Toast.makeText(getApplicationContext(), ""+result, Toast.LENGTH_LONG).show();
}
else
edit_location.setText(result);
str_location= edit_location.getText().toString();
}
@Override
protected void onPreExecute()
{
if(flagsearch)
{
pd = ProgressDialog.show(Main_Search.this, "","Please wait...");
}
}
}
我在主线程上调用异步类
mainAdapter mm= new mainAdapter();
String url="http://www.jobdiagnosis.com/servicesearch.php?keyword="+str_desc+
"&location="+str_location;
url= url.replace(" ","%20");
mm.execute(url);
程序运行良好,但某些站点从服务器获取数据需要很长时间,然后我想设置 time_out 但我不知道设置 Time_out
请帮助我使用 TIME_OUT 并告诉我为什么获取数据需要时间?
我真的很抱歉我的英语不好。