다음은 listview에 대한 사용자 정의 목록 어댑터 코드입니다. 내 코드에서 "not null"토큰을 주석 처리하면 어댑터가 완벽하게 작동합니다. 즉, 뷰 소유자가없는 것입니다. 누군가 내가 여기있는 문제로 나를 도울 수 있습니까?Viewholder가 사용자 정의 어댑터에서 작동하지 않습니다.
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.eachlist, viewGroup, false);
if (this.subject==null && this.percentage==null && this.happen==null && this.missed==null) {
Log.d("null cha","error");
subject = (TextView) row.findViewById(R.id.subjectname);
happen=(TextView)row.findViewById(R.id.attended);
missed=(TextView)row.findViewById(R.id.missed);
percentage=(TextView)row.findViewById(R.id.Attendance);
new viewholder(subject,happen,missed,percentage);
}
else {
subject=viewholder.subject;
happen=viewholder.happen;
missed=viewholder.missed;
percentage=viewholder.percentage;
}
subject.setText(list.get(i).subject);
happen.setText(String.valueOf(list.get(i).happened));
missed.setText(String.valueOf(list.get(i).missed));
percentage.setText(String.valueOf(list.get(i).percentage));
return row;
}
static class viewholder{
static TextView subject;
static TextView happen;
static TextView missed;
static TextView percentage;
viewholder(TextView subject,TextView happen,TextView missed,TextView percentage){
this.subject=subject;
this.happen=happen;
this.missed=missed;
this.percentage=percentage;
}
}
잘못하고 있습니다. 이 자습서를 확인하십시오. http://www.javacodegeeks.com/2013/09/android-viewholder-pattern-example.html –
제대로 하시겠습니까? "뷰 홀더"의 전체적인 요점은 UI를 팽창시키지 않고 이미 캐싱 된 UI를 검사하는 것입니다. 뷰에 태그를 설정하고이 태그가 ViewHolder 클래스의 인스턴스를 나타내는 지 여부를 확인하여이 작업을 수행 할 수 있습니다. 자세한 예제는 http://www.javacodegeeks.com/2013/09/android-viewholder-pattern-example.html을 참조하고 .getTag() 및 .setTag()를 사용하여 비트를 이해해야합니다. – kha