如何“顺利"加载Listview在安卓中 [英] How to load the Listview "smoothly" in android

查看:25
本文介绍了如何“顺利"加载Listview在安卓中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据从光标加载到列表视图,但我的列表视图并未真正显示平滑".当我在 ListView 中的 scollbar 上上下拖动时,数据会发生变化.有些项目在我的列表中看起来像是重复显示.我有一个复杂的 ListView"(两个文本视图,一个图像视图)所以我使用 newView()、bindView() 来显示数据.有人可以帮我吗?

I load data from Cursor to listview, but my Listview not really display "smooth". The data change when I drag up and down on the scollbar in my ListView. And some items look like duplicate display in my list. I hava a "complex ListView" (two textview, one imageview) So I used newView(), bindView() to display data. Can someone help me?

推荐答案

我将向您描述如何解决您遇到的此类问题.也许这会对您有所帮助.

I will describe you how to get such issue that you have. Possibly this will help you.

所以,在列表适配器中你有这样的代码:

So, in list adapter you have such code:

public View getView(int position, View contentView, ViewGroup arg2)
    {
        ViewHolder holder;

        if (contentView == null) {
            holder = new ViewHolder();
            contentView = inflater.inflate(R.layout.my_magic_list,null);
            holder.label = (TextView) contentView.findViewById(R.id.label);
            contentView.setTag(holder);
        } else {
            holder = (ViewHolder) contentView.getTag();
        }

        holder.label.setText(getLabel());

        return contentView;
    }

如您所见,我们仅在检索到持有者后才设置列表项值.

As you can see, we set list item value only after we have retrieved holder.

但是如果你将代码移到上面的 if 语句中:

But if you move code into above if statement:

holder.label.setText(getLabel());

所以它会像下面这样处理:

so it will look after like below:

if (contentView == null) {
   holder = new ViewHolder();
   contentView = inflater.inflate(R.layout.my_magic_list,null);
   holder.label = (TextView) contentView.findViewById(R.id.label);
   holder.label.setText(getLabel());
   contentView.setTag(holder);
}

您将使用列表项重复获得当前的应用程序行为.

you will have your current application behavior with list item duplication.

可能会有所帮助.

这篇关于如何“顺利"加载Listview在安卓中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆