Im實現ViewHolder。即時通訊使用此嘖嘖:Link實現ViewHolder的問題,ObjectItem無法解析爲類型
這是代碼:
@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」。那個班從哪裏來的?
也不識別同一行上的「數據」。
我應該怎麼做?本教程不解釋它..
謝謝!
我想你還沒有關注該博客的完整。檢查我的帖子 – Raghunandan