简体   繁体   中英

How to add seprator between item in recycler view?

I want to add separator line between items but after few items.I have searched for it & got the item decoration but i want to do it after few items not for every single item.

Example:- 我的形象

Check out this tutorial - http://android.amberfog.com/?p=296 Basically you have to check the method in the adapter class

@Override
    public int getItemViewType(int position) {
        return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
    }

Accordingly decide the viewtype according to the position of the item and in the getView() method of the adapter switch between the views to inflate according to the viewType retrieved from the getItemViewType() method

 switch (type) {
                case TYPE_ITEM:
                    convertView = mInflater.inflate(R.layout.item1, null);
                    holder.textView = (TextView)convertView.findViewById(R.id.text);
                    break;
                case TYPE_SEPARATOR:
                    convertView = mInflater.inflate(R.layout.item2, null);
                    holder.textView = (TextView)convertView.findViewById(R.id.textSeparator);
                    break;
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM