什麼是一回事,如果(converView == NULL){} 其他 { } 什麼 如果我避免寫其他部分,以及它如何影響我的代碼? 我只是想知道如果它沒有其他部分工作正常。有人可以解釋有關convertview的gettag和settag嗎?在Android的名單適配器,如果convertView是什麼空不空?誰能請在下面getView方法解釋
public View getView(int position, View convertView, ViewGroup parent) {
DeviceViewHolder holder = null;
mSelectedDeviceBin = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.single_device_view, null);
holder = new DeviceViewHolder();
holder.deviceId = (TextView) convertView
.findViewById(R.id.deviceId);
holder.deviceType = (TextView) convertView
.findViewById(R.id.deviceType);
convertView.setTag(holder);
} else
holder = (DeviceViewHolder) convertView.getTag();
// Populating the views
holder.deviceId.setText(mSelectedDeviceBin.getDeviceBinId());
StringBuilder deviceCount = new StringBuilder();
deviceCount.append("");
double count = mSelectedDeviceBin.getQtyStock();
deviceCount.append(count);
String deviceCountString = deviceCount.toString();
holder.deviceType.setText("Total number of Items:"
+ deviceCountString);
return convertView;
}
[ListView的世界](http://www.youtube.com/watch?v=wDBM6wVEO70)是最好的答案。這是一個1小時的Google IO演示文稿,但這不是浪費時間 – gunar
[How ListView的回收機制的工作原理]可能的重複(http://stackoverflow.com/questions/11945563/how-listviews-recycling-mechanism-works) –