下面是用于列表视图的自定义列表适配器的代码。如果我在我的代码中注释掉“not null”标记,即没有我的视图持有者,适配器将完美运行。有人可以帮我解决我在这里遇到的问题吗?
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;
}
}