Best way to create and process a list view with different lines

In my application, I display the data in a list. It looks like below.

enter image description here

Each line in a list is different (i.e. has a different presentation structure). But each line consists of 1 to many subheadings (all subordinates are the same).

Problem: if you are trying to inflate lines from xml, then I need to have xml with 1. 2 sub-views 2. 3 sub-views 3. 5 approaches, etc.

If I try to build the rows dynamically, then I will not be able to use the holder template or the reusability of Listview. And I end up creating subviews if the number of subviews in the returned view is less than required or deleted in case the subviews are more than required.

, listview, ?

Edit:

ArrayAdapter getView, getViewTypeCount, getItemViewType

@Override
public int getItemViewType(int position) {
    return mListItems.get(position).getViewToBeRenderened().getViewId();
}

@Override
public int getViewTypeCount() {     
    return AppConstants.VwViewTypes.values().length;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    final VWListItem listItem = mListItems.get(position);
    if(listItem == null || listItem.getViewToBeRenderened() == null){
        return convertView;
    }       
    VWView renderingView = listItem.getViewToBeRenderened();

    if(convertView == null ){           
        convertView = renderingView.buildView(mContext.appContext);

    }

                ...
}

, 2-3 . xml , .

, . . , .

0
2

, getViewTypeCount() getItemViewType(), , int, getViewTypeCount(). , 2, 2 convertView.

+4

ListView , . , getViewType - , : linearlayout, . , listview . linearlayout .

0

Source: https://habr.com/ru/post/1599041/


All Articles