0

First of all,I am sorry if my question is meaningless or wrong.

I need to add textview as the footer view to listview ,and that footer view should be repeated for particular number of items.

For example,

If I am having 50 items in a list, whenever I am displaying it in listview , the textview should be displayed below the each group of 10 items (That is the textview should separate 10 items).

Can anyone help me please. I don't even know "using footer view to achieve this is right or not". Thanks!

Jyoti JK
  • 2,141
  • 1
  • 17
  • 40

2 Answers2

0

You could @Override getItemViewType and return 2 type of views based on the position (you set a condition there). Also, in onBindViewHolder (if you use a Recyclerview, and I suggest you to do that) you will check which view was returned and what data to fetch. This post should help you understand perfectly.

Ionut J. Bejan
  • 734
  • 11
  • 28
  • Thanks, I just add textview to the layout and make it visible when the condition is satisfied in my adapter. – Jyoti JK Nov 16 '17 at 09:05
  • Sure, you could do that, but you might find that sometimes doesn't work as you expected, and here I mean upon scrolling. But is your call, Glad I could help – Ionut J. Bejan Nov 16 '17 at 09:08
  • yeah,if number of items is increased in listview, It doesn't work as what i need :( – Jyoti JK Nov 16 '17 at 09:12
  • So go for my solution, I used same thing on a `RecyclerView` for a chat actually. Had two cases, `message received` and `message sent`. Number of items was changing and it worked like a charm – Ionut J. Bejan Nov 16 '17 at 09:15
0

First @override below function in your adapter

 @Override
    public int getItemViewType(int position) {
        if (position == 0) return 1;
        else return 2;
    }
 }

After that check returning positions in @onBindViewHolder and manage your data according to that. Hope this will help you.

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49