2017-04-13 93 views
0

我想在列表中添加多个数组列表,并使用具有节的自定义适配器在列表视图中显示。我在这里试过是我的代码,我试图如何在列表中动态添加多个数组列表

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); 

但它没有显示预期的效果 任何建议或帮助需要

回答

0

你想要的是一个列表的列表!

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... 
} 

要合并3数组列表至一个

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

参考: - https://stackoverflow.com/a/8625256/7795876

+0

我想在一个列表中添加多个阵列列表和要在列表视图 –

+0

HTTP显示:/ /stackoverflow.com/a/15213992/7795876这样? – Hangman

+0

我有5个数组列表,并与不同的模型类,我想显示这些在一个单一的列表视图与部分标题一个接一个 –