【问题标题】:How to dynamically add multiple array-list in a List如何在列表中动态添加多个数组列表
【发布时间】:2017-09-09 05:09:58
【问题描述】:

我想在一个列表中添加多个数组列表,并使用带有部分的自定义适配器在列表视图中显示。我试过这里是我试过的代码

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

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

【问题讨论】:

    标签: android list listview arraylist android-custom-view


    【解决方案1】:

    你想要的是一个列表!

    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

    【讨论】:

    • 我想在一个列表中添加多个数组列表并希望在列表视图中显示
    • 我有 5 个数组列表和不同的模型类,我想在一个列表视图中显示这些,一个又一个的部分标题
    • 不起作用,因为我在每个数组列表中都有不同的数据类型,现在对部分有所了解
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 2020-04-05
    相关资源
    最近更新 更多