Im implementing a ViewHolder. Im using this tut: Link
And this is the code:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
/*
* The convertView argument is essentially a "ScrapView" as described is Lucas post
* http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
* It will have a non-null value when ListView is asking you recycle the row layout.
* So, when convertView is not null, you should simply update its contents instead of inflating a new row layout.
*/
if(convertView==null){
// inflate the layout
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(position, parent, false);
// well set up the ViewHolder
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.image= (ImageView) convertView.findViewById(R.id.image);
// store the holder with the view.
convertView.setTag(viewHolder);
}else{
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (ViewHolder) convertView.getTag();
}
// object item based on the position
ObjectItem objectItem = data[position];
// assign values if the object is not null
if(objectItem != null) {
// get the TextView from the ViewHolder and then set the text (item name) and tag (item ID) values
viewHolder.title.setText(objectItem.itemName);
viewHolder.title.setTag(objectItem.itemId);
}
return convertView;
}
Now the problem is that I dont know what is "ObjectItem". where did that class come from?
also "data" on the same row is not recognized.
How should I do it? the tutorial doesnt explain it..
Thanks!
ObjectItem
is a wrapper for the data. From what you wrote, I can see:and you can fill it up, this way: