:
View v;
// if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.icon, null);
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText(kraj[position]);
ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setImageResource(mThumbIds[position]);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv.setLayoutParams(new LinearLayout.LayoutParams(mniejszy, mniejszy));
// } else {
// v = (View) convertView;
// }
return v;
이
내가의 코드의 일부를 가지고 튜토리얼입니다 처음에는 화면에 표시됨)
GridView
이 스크롤 될 때 (
convertView
이 null이 아닐 때) 행 뷰를 재활용하므로 새 이미지/텍스트로 업데이트하지 않은 이전 행으로 끝납니다. 코드는 다음과 같이해야한다 : 당신이 경험하는 것은 사실
recycled view
에 이전에 할당 된 데이터가 때문에 아마
View v;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.icon, null);
} else {
v = (View) convertView;
}
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText(kraj[position]);
ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setImageResource(mThumbIds[position]);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv.setLayoutParams(new LinearLayout.LayoutParams(mniejszy, mniejszy));
return v;
좋아, 그렇다면 "if"는 무엇입니까? convertView == 0인지 확인하지 않고 정상적으로 작동합니까? – Lukis
'if'는 성능 향상입니다. 뷰가 이미 초기화 된 경우, 왜 다시 플레 넘이됩니까? 당신은 작은 목록에서 그것을 알아 채지 못할 수도 있지만 낭비 적이 아닌 큰 목록에서는 많은 도움이됩니다. –
의미가 있습니다! Thx 당신의 도움. 내가 더 많은 평판을 얻으면, 나는 당신을 투표 할 것입니다. – Lukis