Set up ListView from a String[][]



I have a String[][] of data and am trying to make a custom listView from it here is the data



String[][] myDataArray = {{"cat1","cat2","cat3","cat4"},
{"dog1","dog2","dog3"},
{"lion1"},
{"monkey1","monkey2"}};


And now here is how I am trying to display this data in my list view. I want each array with in the array to have its own row. So all the cats will be in one row (cell), all the dogs will be in row and so on. Here is a picture to make it clear each item in the row, is a textView.


enter image description here


I have made an cell_4.xml, cell_3, cell_2.xml, cell_1.xml layout file for each of the rows. And then in the activity that I am trying to show this, I just have a plain old listView.


Now I am not quite sure how to edit/ adapt the data I have to display it in this way. So that it uses the correct cell layout for each array within the String[]. I was think about using a switch statement to get the number of items in each inner array. But have been having some trouble with the ArrayAdapter. To get it set up.


I have looked at a couple of examples on stack like this one Custom ListView Android to try and figure this out but can't get it.


No comments:

Post a Comment