I m working with BaseAdapter
class and i get an ClassCastException
error in getView
method when i try to cast my viewHolder class.
Here is my code:
public View getView(int position, View convertView, ViewGroup parent){
// TODO Auto-generated method stub
NoteItem noteItem = list.get(position);
TextView tv;
LinearLayout ll;
if(convertView == null){
convertView = inflater.inflate(R.layout.dialog_listitem_note, null);
ll = (LinearLayout) convertView.findViewById(R.id.llNote);
tv = (TextView) convertView.findViewById(R.id.tvNoteItem);
convertView.setTag(new NoteItemViewHolder(tv, ll));
ll.setOnClickListener(new OnClickListener(){...});
}else{
NoteItemViewHolder viewHolder = (NoteItemViewHolder) convertView.getTag(); //ClassCastException error here
ll = viewHolder.getLl();
tv = viewHolder.getName();
}
tv.setText(noteItem.getName());
ll.setTag(noteItem);
...
return convertView;
}
private class NoteItemViewHolder{
TextView name;
LinearLayout ll;
public NoteItemViewHolder(TextView name, LinearLayout ll){
this.name = name;
this.ll = ll;
}
public TextView getName(){
return name;
}
public LinearLayout getLl(){
return ll;
}
}
Dont get why this error occurs, please help.
No comments:
Post a Comment