我想要在JSONAdapter
AsyncTask
上更新自定义onPostExecute
课程。但是,尽管我致电notifyDataSetChanged()
,尽管getCount()
发生了变化,但getView
永远不会被调用。
private class JSONAdapter extends BaseAdapter implements ListAdapter {
private final Activity activity;
private JSONAdapter(Activity activity) {
this.activity = activity;
}
@Override public int getCount() {
if (result == null) {
return 0;
} else {
return result.length();
}
}
@Override public JSONObject getItem(int position) {
return result.optJSONObject(position);
}
@Override public long getItemId(int position) {
JSONObject jsonObject = getItem(position);
return jsonObject.optLong("id");
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_item, parent, false);
TextView textView1 = (TextView) rowView.findViewById(R.id.firstLine);
TextView textView2 = (TextView) rowView.findViewById(R.id.secondLine);
try {
textView1.setText(result.getJSONObject(position).getString("image"));
textView2.setText(result.getJSONObject(position).getString("distance"));
} catch (JSONException e) {
e.printStackTrace();
}
return rowView;
}
}
有人能看出我做错了吗?
答案 0 :(得分:0)
我没弄清楚为什么notifyDataSetChanged()无法正常工作,但我设法通过每次重新创建和重置适配器来解决问题。