我有一個GridView加載了一堆自定義視圖。當我向上或向下滾動時,之前屏幕上顯示的視圖現在被替換爲不同的視圖。任何想法爲什麼發生這種情況Android 2.3:GridView滾動後出現故障
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;
}
應該複製它! – Mikey