我的列表视图没有填充我从MySQL数据库中提取的数据。我已经测试了web服务,一切都很完美。我正在调试它,我注意到当我在我的异步任务中设置断点时,它永远不会出现在那里。我离开了execute命令,但它从未进入内部。一切运行正常,没有任何错误。我是个新手,很困惑,请温文点。
public class Favorites extends Activity{
UserFunctions userFunctions = new UserFunctions();
ArrayList<String> zipcodes = new ArrayList<String>(0);
ArrayAdapter<String> arrayAdapter1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favoritespage);
arrayAdapter1 = new ArrayAdapter<String>(Favorites.this,android.R.layout.activity_list_item,zipcodes);
new DownloadDataTask().execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main_screen, menu);
return true;
}
private class DownloadDataTask extends AsyncTask<JSONArray, JSONArray, ArrayList<String> > {
@Override
protected ArrayList<String> doInBackground(JSONArray... params) {
JSONArray json = userFunctions.ziplistrequest("37.5", "140.45", "20");
for(int i=0; i < json.length() ; i++) {
JSONObject jarray = null;
try {
jarray = json.getJSONObject(i);
String zip = jarray.getString("ZIPCODE");
zipcodes.add(zip);
arrayAdapter1.add(zip);
Log.d(zip,"Output");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return zipcodes;
}
protected void onPostExecute(){
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(arrayAdapter1);
}
}如果需要任何额外的答案,请让我知道。
发布于 2013-02-04 19:29:47
好东西。我将添加我的评论作为对Q&A闭包和纯粹的SO point贪婪的回答:)
如果将调试点直接放在异步任务doInBackground上,会发生什么?清理和构建您的项目(如果使用Eclipse IDE),以防出现一些编译器/类生成问题
https://stackoverflow.com/questions/14678998
复制相似问题