【问题标题】:Android UI ListViewAndroid UI 列表视图
【发布时间】:2012-11-07 23:24:51
【问题描述】:

我有一个包含许多类别的测验应用程序:

第 1 类

  • 列表项 1
  • 列表项 2

第 3 类

第 4 类

第 5 类

  • 列表项 1
  • 列表项 2
  • 列表项 3

因此,类别要么是指作为类别标题的一般不可选择类别,要么是实际类别。例如,假设类别 1 是水果,可能会有关于苹果和香蕉的问题。苹果和香蕉将是可选的,并且还会显示类别中有多少问题。但是第 3 类是蔬菜,它本身是可选择的,例如 100 个问题。

现在有可能将其变成每个类别的可扩展列表视图。但是,没有其他问题的类别是不可扩展的。是否有可能将按钮放在可扩展列表视图中,还是必须分开?复选框呢?

谢谢

【问题讨论】:

    标签: android button user-interface expandablelistview


    【解决方案1】:

    您可以使用以下库轻松创建分段列表。您可以在六行中创建它

    所以你可以在列表视图中为每个类别设置标题

    sectioned List ibrary

    分段列表示例

    如何实现,

       // 1. Your data source
        String[] books = new String[] {
            "A Item", "F Item", "D Item", 
            "H Item", "T Item", 
            "A Item 1", "T Item 2"
        };
    
        // 2. Sort it
        Arrays.sort(books, 0, books.length, Collator.getInstance());
    
        // 3. Create your adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
                android.R.layout.simple_list_item_1, books);
    
        // 4. Create a Sectionizer
        Sectionizer<String> alphabetSectionizer = new Sectionizer<String>() {
    
            @Override
            public String getSectionTitleForItem(String categoryName) {
                return bookName;
            }
        };
    
        // 5. Wrap your adapter within the SimpleSectionAdapter
        SimpleSectionAdapter<String> sectionAdapter = new SimpleSectionAdapter<String>(this, 
                adapter, R.layout.section_header, R.id.title, alphabetSectionizer);
    
        // 6. Set the adapter to your ListView
        setListAdapter(sectionAdapter);
    

    【讨论】:

      猜你喜欢
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多