Android 为什么没有取得进展
我通过php脚本和客户端的httpclient从网站获取数据。加载数据时,我想在操作栏中显示progressbar。问题是progressbar没有显示。代码如下所示:Android 为什么没有取得进展,android,http,progress-bar,Android,Http,Progress Bar,我通过php脚本和客户端的httpclient从网站获取数据。加载数据时,我想在操作栏中显示progressbar。问题是progressbar没有显示。代码如下所示: public class MainActivity extends Activity { private ListView listView1; private String str = null; private Classification[] classification_datas; @
public class MainActivity extends Activity {
private ListView listView1;
private String str = null;
private Classification[] classification_datas;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
ActionBarUtils.setActionBar(this);
AsyncData data=new AsyncData();
data.execute("http://kurdshopping.net/apj/category.php");
try {
classification_datas = data.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
ClassificationAdapter adapter=new ClassificationAdapter(this, R.layout.listview_item_row, classification_datas);
listView1=(ListView) findViewById(R.id.listViewAllItems);
View header=(View) getLayoutInflater().inflate(
R.layout.listview_header_row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent subcategory = new Intent(MainActivity.this,
SubCategoryActivity.class);
subcategory
.putExtra("id", classification_datas[position - 1].id);
startActivity(subcategory);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
break;
case R.id.action_all:
Intent allitemIntent = new Intent(MainActivity.this,
AllItemsActivity.class);
startActivity(allitemIntent);
break;
case R.id.action_search:
Intent search = new Intent(this, SearchDialogActivity.class);
startActivity(search);
break;
}
return super.onOptionsItemSelected(item);
}
private class AsyncData extends AsyncTask<String, Void, Classification[]>{
private ProgressDialog pd;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd=ProgressDialog.show(MainActivity.this, "Loading. Please wait", "Loading Please wait");
pd.show();
setProgressBarIndeterminateVisibility(true);
}
@Override
protected Classification[] doInBackground(String... arg0) {
final Classification classification_data[] = new Classification[12];
try {
str = CustomHttpClient
.executeHttpGet(arg0[0]);
// str = CustomHttpClient
// .executeHttpGet("http://kurdshopping.net/apj/category.php");
JSONArray array = null;
array = new JSONArray(str);
JSONObject jdata = null;
jdata = array.getJSONObject(0);
classification_data[0] = new Classification(R.drawable.motor_icon,
jdata.getString("name")
/* res.getString(R.string.Motor) */, jdata.getInt("id"));
jdata = array.getJSONObject(1);
classification_data[1] = new Classification(R.drawable.electronics,
jdata.getString("name")
/* res.getString(R.string.Electronics) */,
jdata.getInt("id"));
jdata = array.getJSONObject(2);
classification_data[2] = new Classification(
R.drawable.property_icon, jdata.getString("name")
/* res.getString(R.string.Property) */, jdata.getInt("id"));
jdata = array.getJSONObject(3);
classification_data[3] = new Classification(R.drawable.animal_icon,
jdata.getString("name")
/* res.getString(R.string.Animals) */, jdata.getInt("id"));
jdata = array.getJSONObject(4);
classification_data[4] = new Classification(R.drawable.house_icon,
jdata.getString("name")
/* res.getString(R.string.House) */, jdata.getInt("id"));
jdata = array.getJSONObject(5);
classification_data[5] = new Classification(R.drawable.gold,
jdata.getString("name")/* res.getString(R.string.Gold) */,
jdata.getInt("id"));
jdata = array.getJSONObject(6);
classification_data[6] = new Classification(
R.drawable.farming_icon, jdata.getString("name")
/* res.getString(R.string.Farming) */, jdata.getInt("id"));
jdata = array.getJSONObject(7);
classification_data[7] = new Classification(
R.drawable.bussines_icon, jdata.getString("name")
/* res.getString(R.string.Business) */, jdata.getInt("id"));
jdata = array.getJSONObject(8);
classification_data[8] = new Classification(R.drawable.sports_icon,
jdata.getString("name")
/* res.getString(R.string.Sports) */, jdata.getInt("id"));
jdata = array.getJSONObject(9);
classification_data[9] = new Classification(
R.drawable.music_icon,
jdata.getString("name")/* res.getString(R.string.Music) */,
jdata.getInt("id"));
jdata = array.getJSONObject(10);
classification_data[10] = new Classification(
R.drawable.fashion_icon, jdata.getString("name")
/* res.getString(R.string.Fashion) */, jdata.getInt("id"));
jdata = array.getJSONObject(11);
classification_data[11] = new Classification(R.drawable.jobs_icon,
jdata.getString("name")/* res.getString(R.string.Jobs) */,
jdata.getInt("id"));
} catch (NotFoundException e) {
} catch (JSONException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return classification_data;
}
@Override
protected void onPostExecute(Classification[] result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pd.dismiss();
setProgressBarIndeterminateVisibility(false);
}
}
}
公共类MainActivity扩展活动{
私有列表视图列表视图1;
私有字符串str=null;
私有分类[]分类数据;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
StrictMode.setThreadPolicy(新的StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE\u不确定\u进度);
setContentView(R.layout.activity_main);
ActionBarUtils.setActionBar(本);
AsyncData=新的AsyncData();
执行(“http://kurdshopping.net/apj/category.php");
试一试{
分类_data=data.get();
}捕捉(中断异常e){
e、 printStackTrace();
}捕获(执行例外){
e、 printStackTrace();
}
ClassificationAdapter=新的ClassificationAdapter(此,R.layout.listview\u item\u行,classification\u数据);
listView1=(ListView)findViewById(R.id.listViewAllItems);
视图标题=(视图)GetLayoutFlater()。充气(
R.layout.listview_标题_行,空);
listView1.addHeaderView(标题);
listView1.setAdapter(适配器);
listView1.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共链接(AdapterView arg0、视图arg1、,
整数位置,长arg3){
意向子类别=新意向(MainActivity.this,
子类别(活动类);
子类别
.putExtra(“id”,分类数据[position-1].id);
startActivity(子类别);
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
开关(item.getItemId()){
案例android.R.id.home:
打破
案例R.id.action\u全部:
Intent allitemIntent=新的Intent(MainActivity.this,
AllItemsActivity.class);
星触觉(allitemIntent);
打破
案例R.id.行动搜索:
意向搜索=新意向(此,SearchDialogActivity.class);
星触觉(搜索);
打破
}
返回super.onOptionsItemSelected(项目);
}
私有类AsyncData扩展AsyncTask{
私营部门;
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
pd=ProgressDialog.show(MainActivity.this,“正在加载。请等待”,“正在加载请等待”);
pd.show();
SetProgressBarInDeterminateVibility(真);
}
@凌驾
受保护的分类[]doInBackground(字符串…arg0){
最终分类数据[]=新分类[12];
试一试{
str=CustomHttpClient
.executeHttpGet(arg0[0]);
//str=CustomHttpClient
//.executeHttpGet(“http://kurdshopping.net/apj/category.php");
JSONArray数组=null;
数组=新的JSONArray(str);
JSONObject jdata=null;
jdata=array.getJSONObject(0);
分类\u数据[0]=新分类(R.drawable.motor\u图标,
getString(“名称”)
/*res.getString(R.string.Motor)*/,jdata.getInt(“id”);
jdata=array.getJSONObject(1);
分类\u数据[1]=新分类(R.drawable.electronics,
getString(“名称”)
/*res.getString(R.string.Electronics)*/,
jdata.getInt(“id”);
jdata=array.getJSONObject(2);
分类\u数据[2]=新分类(
R.drawable.property_图标,jdata.getString(“名称”)
/*res.getString(R.string.Property)*/,jdata.getInt(“id”);
jdata=array.getJSONObject(3);
分类数据[3]=新分类(R.drawable.animal_图标,
getString(“名称”)
/*res.getString(R.string.Animals)*/,jdata.getInt(“id”);
jdata=array.getJSONObject(4);
分类数据[4]=新分类(R.drawable.house_图标,
getString(“名称”)
/*res.getString(R.string.House)*/,jdata.getInt(“id”);
jdata=array.getJSONObject(5);
分类_数据[5]=新分类(R.drawable.gold,
jdata.getString(“name”)/*res.getString(R.string.Gold)*/,,
jdata.getInt(“id”);
jdata=array.getJSONObject(6);
分类_数据[6]=新分类(
R.drawable.u图标,jdata.getString(“名称”)
/*res.getString(R.string.Farming)*/,jdata.getInt(“id”);
jdata=array.getJSONObject(7);
分类\u数据[7]=新分类(
R.drawable.bussines_图标,jdata.getString(“名称”)
/*res.getString(R.string.Business)*/,jdata.getInt(“id”);
public class MainActivity extends Activity {
private ListView listView1;
private String str = null;
private Classification[] classification_datas;
private ProgressDialog pd;
private ProgressDialog pd;
pd = new ProgressDialog(MainActivity.this);
pd.setCancelable(true);
pd.setTitle("Please wait!");
pd.setMessage("Connecting...");
pd.show();