【问题标题】:How to set the default expand limit to 4 for expandablelistview ?如何将可扩展列表视图的默认扩展限制设置为 4?
【发布时间】:2015-11-04 12:35:49
【问题描述】:

我正在使用可扩展列表视图。默认情况下,我必须将组列表视图扩展为 4。有可能实现吗?

【问题讨论】:

    标签: java android android-intent android-activity expandablelistview


    【解决方案1】:

    您可以在组列表视图中定义固定值,如下所示:

    private void prepareListData() {
            listDataHeader = new ArrayList<String>();
            listDataChild = new HashMap<String, List<String>>();
    
            // Adding parent data
            listDataHeader.add("first");
            listDataHeader.add("second");
            listDataHeader.add("third");
            listDataHeader.add("fourth");
    
            // Adding child data
            List<String> first = new ArrayList<String>();
            first.add("The Shawshank Redemption");
            first.add("The Godfather");
            first.add("The Godfather: Part II");
            first.add("Pulp Fiction");
            first.add("The Good, the Bad and the Ugly");
            first.add("The Dark Knight");
            first.add("12 Angry Men");
    
            List<String> second = new ArrayList<String>();
            second.add("The Conjuring");
            second.add("Despicable Me 2");
            second.add("Turbo");
            second.add("Grown Ups 2");
            second.add("Red 2");
            second.add("The Wolverine");
    
            List<String> third = new ArrayList<String>();
            third.add("2 Guns");
            third.add("The Smurfs 2");
            third.add("The Spectacular Now");
            third.add("The Canyons");
            third.add("Europa Report");
    
            listDataChild.put(listDataHeader.get(0), first); // Header, Child data
            listDataChild.put(listDataHeader.get(1), second);
            listDataChild.put(listDataHeader.get(2), third);
        }
    

    【讨论】:

    • 这对我所需要的没有帮助。
    • 你希望列表视图默认显示 4 个孩子 ..?对
    • 完全正确。当它展开时显示特定组的所有子项。
    • 如果子长度 child = new ArrayList(); child.add(""); child.add(""); child.add(""); child.add(""); child.add("");
    • 当你想在那个特定的孩子中添加价值..那么你可以在像 child.set(possition,value); 这样的 arralist 中设置该值在刷新列表之后,请在特定位置添加您的值
    猜你喜欢
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多