我的列表视图没有填充我从 MySQL 数据库中提取的数据。我已经测试了网络服务,一切都很完美。我正在调试它,我注意到当我在我的异步任务中设置一个断点时,它从来没有去那里。我从执行命令中走出来,它从来没有进去过。一切运行良好,没有错误。我很困惑和新的,请温柔。
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);
}
}
如果需要任何其他答案,请告诉我。