我覺得這有點奇怪。我有一個Fragement活動,有一個視圖尋呼機和4個標籤片段。Android Listview在片段中,項目顯示爲空內容
在三個選項卡中我有listviews。每次我打開我的應用程序並滾動到第二個選項卡,我有我的第一個listview和列表視圖中的兩個項目,該項目的內容是空的。直到我滾動到第4個選項卡並返回到第二個,因此對該片段進行刷新是我的猜測。
這裏是第二個片段第一次打開時: http://postimg.org/image/84413xncd/
&這裏是通過滾動到聯繫人,然後再返回打開了同一個片段: http://postimg.org/image/afhhle3bn/
這是我的設置列表中該片段,helper.list是一個List。
public void onResume() {
super.onResume();
if (helper.news != null) {
NewsArrayAdapter newsAdapter = new NewsArrayAdapter(getActivity(), 0, helper.news);
list.setAdapter(newsAdapter);
}
}
這是我的自定義適配器:
public class NewsArrayAdapter extends ArrayAdapter<JSONObject> {
private Context context;
private List<JSONObject> items;
MainHelper helper = null;
public NewsArrayAdapter(Context context, int layoutResourceId, List<JSONObject> items) {
super(context, layoutResourceId, items);
this.context = context;
this.items = items;
helper = MainHelper.getHelper();
}
@Override
public View getView(int p, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.single_row_news, parent, false);
TextView name = (TextView) rowView.findViewById(R.id.name);
name.setText(items.get(p).optString("name"));
name.setTypeface(Font.rLight(context));
TextView date = (TextView) rowView.findViewById(R.id.date);
date.setText(Methods.getMethods().getDate(context, items.get(p).optLong("dateAdded"), R.string.date_format_date_month));
date.setTypeface(Font.rLight(context));
ProgressBar spinner = (ProgressBar) rowView.findViewById(R.id.spinner);
ImageView image = (ImageView) rowView.findViewById(R.id.thumbnail);
if (items.get(p).optString("photoURL") == null || items.get(p).optString("photoURL").equals("")) {
image.setVisibility(View.GONE);
spinner.setVisibility(View.GONE);
} else Methods.getMethods().loadImageView(context, items.get(p).optString("photoURL"), image, spinner);
return rowView;
}
}
圖像是從URL裝入一個的AsyncTask,所以換句話說,是一個小的延遲給他們,這就是爲什麼我認爲他們表現,但爲什麼不是文字?
你檢查過'helper.news!= null'嗎? – MalaKa
謝謝@MalaKa,就是這樣! –
@just_user即時通訊面臨一些類似的問題,你是如何解決你的問題?我使用ListView與嵌套片段時,我添加一個項目列表圖像得到更新,但TextView保持空。請與我分享您的解決方案。謝謝 –