片段中的Android Listview,项目显示空内容

时间:2014-03-19 12:16:26

标签: android listview android-fragments

我发现这有点奇怪。我有一个带有视图寻呼机的Fragement活动和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;
    }
}

图像是从asynctask中的url加载的,换句话说是对它们的一个小延迟,这就是为什么我认为它们显示,但为什么不显示文本?

1 个答案:

答案 0 :(得分:-1)

使用延迟加载进行下载,并在listView中显示来自服务器的图像。见this

相关问题