0
我已經創建了一個示例,根據這個link ListView幾行的不同佈局。這裏是佈局無法更新列表視圖中的不同行我
,因爲我想只有第一行有不同的佈局,每當位置爲0我申請佈局一個(名稱&電話),並休息我申請佈局兩(地址)。
我面對的問題是當我在適配器上觸發notifyDataSetChanged時,只有我的地址被更改,但名稱&電話行,即第一行不更新。當選擇子菜單項時,我正在觸發notifyDataSetChanged。
這是代碼。
public static final int TYPE_ADDRESS = 1;
public static final int TYPE_NAME = 0;
public static final int TYPE_MAX_COUNT =2;
@Override
public int getItemViewType(int position) {
if(position == 0)
return TYPE_NAME;
else
return TYPE_ADDRESS;
}
@Override
public int getViewTypeCount() {
return TYPE_MAX_COUNT;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
int type = getItemViewType(position);
System.out.println("getView " + position + " " + convertView + " type = " + type);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ADDRESS:
convertView = mInflater.inflate(R.layout.layout_address, null);
holder.address = (TextView) convertView.findViewById(R.id.address_id);
holder.address.setText(data.getAddress(position));
break;
case TYPE_NAME:
convertView = mInflater.inflate(R.layout.layout_name, null);
holder.name = (TextView)convertView.findViewById(R.id.name_id);
holder.phone = (TextView)convertView.findViewById(R.id.phone_id);
holder.name.setText(data.getName(position));
holder.phone.setText(data.getPhone(position));
break;
}
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
static class ViewHolder {
TextView address;
TextView name;
TextView phone;
}
bravo !!這是我想要的感謝 – Hunt