if(converView==null) { } else { } 如果我避免编写 else 部分以及它如何影响我的代码怎么办?我只是想知道如果没有其他部分它是否可以正常工作。有人可以解释一下convertview的gettag和settag吗???
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;
}