我正在实现一个 ViewHolder。我正在使用这个 tut:链接
这是代码:
@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;
}
现在的问题是我不知道什么是“ObjectItem”。那门课是从哪里来的?
同一行上的“数据”也无法识别。
我该怎么做?教程没有解释..
谢谢!