滚动时的ListView在ArrayAdapter才能得到的混合起来 [英] ListView in ArrayAdapter order get's mixed up when scrolling

查看:99
本文介绍了滚动时的ListView在ArrayAdapter才能得到的混合起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示图标ImageView的,每行一个TextView自定义ArrayAdapter一个ListView。当我榜上无名足够长的时间让你通过它滚动,顺序开出正确的,但是当我开始向下滚动,一些早期的条目开始重新出现。如果我滚动回涨,旧秩序的变化。反复这样做最终会导致整个列表为了看似随意的。因此,滚动列表或者是造成孩子为了改变,或者绘图不刷新正确。

I have a ListView in a custom ArrayAdapter that displays an icon ImageView and a TextView in each row. When I make the list long enough to let you scroll through it, the order starts out right, but when I start to scroll down, some of the earlier entries start re-appearing. If I scroll back up, the old order changes. Doing this repeatedly eventually causes the entire list order to be seemingly random. So scrolling the list is either causing the child order to change, or the drawing is not refreshing correctly.

这是什么原因这样的事情发生?我所需要的项目被显示给用户的是它们被添加到ArrayList,或者至少保持在一个静态的顺序相同的顺序的顺序。如果我需要提供更详细的信息,请让我知道。任何帮助是AP preciated。谢谢你。

What could cause something like this to happen? I need the order the items are displayed to the user to be the same order they are added to the ArrayList, or at LEAST to remain in one static order. If I need to provide more detailed information, please let me know. Any help is appreciated. Thanks.

推荐答案

我有类似的问题,但单击自定义列表中的项目时,屏幕上的项目会扭转序列。如果我再次点击,他们会反向回到他们最初。

I was having similar issues, but when clicking an item in the custom list, the items on the screen would reverse in sequence. If I clicked again, they'd reverse back to where they were originally.

在阅读完之后,我检查了我的code,我重载getView方法。我得到的观点从convertedView,如果为空,就在那个时候我建我的东西。但是,将一个断点后,我发现它呼吁每一次点击,并在随后的点击这种方法,convertedView是不为空,因此项目没有被设置。

After reading this, I checked my code where I overload the getView method. I was getting the view from the convertedView, and if it was null, that's when I'd build my stuff. However, after placing a breakpoint, I found that it was calling this method on every click and on subsequent clicks, the convertedView was not null therefore the items weren't being set.

下面是一个例子这是什么:

Here is an example of what it was:


public View getView(int position, View convertView, ViewGroup parent)
{
    View view = convertView;
    if (view == null)
    {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.listitemrow, null);

        RssItem rssItem = (RssItem) super.getItem(position);
        if (rssItem != null)
        {
            TextView title = (TextView) view.findViewById(R.id.rowtitle);
            if (title != null)
            {
                title.setText(rssItem.getTitle());
            }
        }
    }
    return view;
}

在微妙的变化是只充气后动为空检查右括号的观点:

The subtle change is moving the close brace for the null check on the view to just after inflating:


public View getView(int position, View convertView, ViewGroup parent)
{
    View view = convertView;
    if (view == null)
    {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.listitemrow, null);
    }
    RssItem rssItem = (RssItem) super.getItem(position);
    if (rssItem != null)
    {
        TextView title = (TextView) view.findViewById(R.id.rowtitle);
        if (title != null)
        {
            title.setText(rssItem.getTitle());
        }
    }
    return view;
}

我希望这可以帮助别人谁遇到同样的问题。

I hope this helps others who experience this same problem.

这篇关于滚动时的ListView在ArrayAdapter才能得到的混合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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