以下是必需的代碼。我試圖在同一列表視圖中使用兩個不同的視圖。我想要一列數組列表被充氣爲行,然後是另一列。但是會發生什麼事情,這些行會相互膨脹。ListView中的行正在彼此膨脹
代碼:
@Override
public int getItemViewType(int position) {
if (position < (mContactsNumber.size())) {
a = 0;
return a;
} else {
a = 1;
return a;
}
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
final int pos = i;
int type = getItemViewType(i);
View v = view;
if (view == null) {
switch (type) {
case 0:
v = mInflater.inflate(R.layout.contacts_row, null);
name = (TextView) v.findViewById(R.id.contact_name);
name.setText(mContactsNames.get(i));
break;
case 1:
v = mInflater.inflate(R.layout.manual_row, null);
mManual = (TextView) v.findViewById(R.id.manual_number);
mSwitch = (SwitchCompat) v.findViewById(R.id.manual_switch);
mManual.setText(mPermanentManual.get(i));
mSwitch.setTag(i);
try {
if (mManualList.contains(mPermanentManual.get(i))) {
mSwitch.setChecked(true);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
return v;
}
您可以檢查http://learnncode.co/2014/01/21/listview-getviewtype-and-getviewtypecount在行動/ – Prachi 2014-11-21 06:22:31