gpt4 book ai didi

安卓 2.3 : GridView out of order after scrolling

转载 作者:太空狗 更新时间:2023-10-29 12:56:03 25 4
gpt4 key购买 nike

我有一个加载了一堆自定义 View 的 GridView。当我向上或向下滚动时,之前离开屏幕的 View 现在被不同的 View 所取代。知道为什么会这样吗?

    public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rLayout = (RelativeLayout)inflater.inflate(R.layout.collection_item, parent, false);

if (convertView == null) { // if it's not recycled, initialize some attributes
ImageView movieImage = (ImageView)rLayout.findViewById(R.id.movieImage);
TextView movieTitle = (TextView)rLayout.findViewById(R.id.movieTitle);
TextView movieDescription = (TextView)rLayout.findViewById(R.id.movieDescription);

movieImage.setImageResource(movies[position]);
movieTitle.setText(movieNames[position]);
movieDescription.setText(movieDescriptions[position]);
} else {
rLayout = (RelativeLayout) convertView;
}
return rLayout;
}

最佳答案

没关系,我想通了。只需将所有初始化代码放入 (convertView == null) 部分和 if/else block 之后的 setter 方法。

关于安卓 2.3 : GridView out of order after scrolling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6680996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com