0

I want to add multiple array-list in a list and display in list-view using custom adapter with section. i have tried here is my code i tried

   for (int i=0;i<mModelJsoncatData.size();i++){
                if (mModelJsoncatData.get(i).getCatName().equals("Eating")) {
                    ListAll.add(new String(mModelJsoncatData.get(i).getCatName()));
                    ListAll.addAll(mModelJsonEating);
                }
                if (mModelJsoncatData.get(i).getCatName().equals("Feeling")) {
                    ListAll.add(new String(mModelJsoncatData.get(i).getCatName()));
                    ListAll.addAll(mModelJsonFeeling);
                }
                if (mModelJsoncatData.get(i).getCatName().equals("Listening to")) {
                    ListAll.add(new String(mModelJsoncatData.get(i).getCatName()));
                    ListAll.addAll(mModelJsonListening);
                }
                if (mModelJsoncatData.get(i).getCatName().equals("Watching")) {
                    ListAll.add(new String(mModelJsoncatData.get(i).getCatName()));
                    ListAll.addAll(mModelJsonWatching);
                }
            }
MAdapter adapter=new MAdapter(this,ListAll);
listview1.setAdapter(adapter); 

but its not showing the desired results any suggestions or help needed

1 Answer 1

0

What you want is a list of lists!

List<List<Integer>> lists = new ArrayList<List<Integer>>();
for (int i = 0; i < 4; i++) {
    List<Integer> list = new ArrayList<>();
    lists.add(list);
    // Use the list further...
}

To Merge 3 arraylist to one

List<String> combined = new ArrayList<String>();
combined.addAll(firstArrayList);
combined.addAll(secondArrayList);
combined.addAll(thirdArrayList);

Reference :-https://stackoverflow.com/a/8625256/7795876

Sign up to request clarification or add additional context in comments.

3 Comments

i want to add multiple array-lists in a list and want to display in listview
i have 5 array list and with different model classes and i want to display these in a single list view with section header one after another
not worked because i have different data types in each array list and now idea about sections

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.