0

I'm trying to convert an IOS app to android and I'm having some issues with things that where very simple in IOS.

My issue right now is that i have a list of Chapters Each chapter is an object of:

{
    String
    int
    List<Paragraph>
}

I need to populate the listView with all the paragraphs for all the chapters and the string in the chapter need to be the header of the section so i will have a a display of

- Chapter header
-- Paragraph
-- Paragraph
-- Paragraph
- Chapter Header
-- Paragraph
-- Paragraph

And so on.... I already thought about creating a list of all the paragraphs from the chapters but then i loose the headers (the sections in my table) so this is no good. I am getting the correct list to the getView method in my adapter but need a way to get things right.

Any one has any idea how to do that in Android?

10x

Erez
  • 1,933
  • 5
  • 29
  • 56

2 Answers2

1

Look you need to do this by using RecylerView rather with listview as it is latest version of listview. You need to write custom adapter with layout of two textview one for heading other for paragraph. Initialize this adapter with your list of objects then in onBinfViewHolder method get each object and show it in list.

Link to recycler view tutorial

Let me know if you required any other help.

Hassan Munir
  • 419
  • 7
  • 24
  • It seems to me that this solution has the same issue as i have. if movies list is just a list of objects, not a list of objects with list. It is just an improvement over the listView. What i need is the second level on to get the an object in the main list (Chapters list) and in it to use the header (String) for the header in the listView and all the paragraphs in each Chapter object as a second level to fill the listView. I can't see who this solution helps... Maybe i'm missing something? Many thinks for the answer – Erez Feb 02 '17 at 07:37
1

Another great approach is to use ExpandableListView. It's a bit more complicated than using a regular ListView or RecyclerView, but you will get the great functionality of expanding and collapsing your content based on the chapter headers.

You can check this article for a tutorial of how to implement it.

Todor Kostov
  • 1,789
  • 1
  • 13
  • 20
  • 1
    10x, This worked with some modifications and playing around, but it worked. I still needed to break the objects but never mind, as long as it is working. I'm guessing that is my skills in Android and there are ways to do this without breaking the objects to string and paragraph. but 10x any way, good enough for now! – Erez Feb 02 '17 at 10:51