여기에 필요한 코드가 있습니다. 동일한 목록보기 내에서 행에 대해 두 가지 다른보기를 사용하려고합니다. 한 세트의 arraylist를 행렬로 부풀게하고 다른 하나를 팽창시켜야합니다. 그러나 행은 서로 부풀려져 팽창합니다.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 -in-action/ – Prachi