如何加载列表视图"顺利"在机器人 [英] How to load the Listview "smoothly" in android

查看:152
本文介绍了如何加载列表视图"顺利"在机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载数据从光标到列表视图,但我的列表视图没有真正显示出平稳。当我在我的ListView的scollbar拖向上和向下的数据变化。而一些项目看起来像在我的列表中的重复的显示。 我哈瓦复杂的ListView(两个TextView的一ImageView的),所以我用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.

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

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.

不过,如果您移动code到上面的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.

可能会有所帮助。

这篇关于如何加载列表视图"顺利"在机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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