android - 需要 Greendroid GDExpandableListActivity 示例

标签 android expandablelistview greendroid

我正在搜索该 Activity 类的任何简单实现。

最佳答案

我会在这里回答我自己的解决方案

import greendroid.app.GDExpandableListActivity;
import greendroid.widget.ActionBarItem.Type;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;

public class ExpListViewActivity extends GDExpandableListActivity {
    private static final String NAME = "NAME";
    private static final String IS_EVEN = "IS_EVEN";

    DataBaseHelper dbHelper;


    private ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addActionBarItem(Type.Add);
    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();


    for (int i = 0; i < 20; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put(NAME, "Item " + i);
        curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for (int j = 0; j < 5; j++) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            children.add(curChildMap);
           // curChildMap.put(NAME, "Child " + j);
            curChildMap.put(IS_EVEN, (j % 2 == 0) ? "Hello " + j: "Good Morning "+ j);
        }
        childData.add(children);
    }

    // Set up our adapter
    mAdapter = new SimpleExpandableListAdapter(
            this,
            groupData,
            android.R.layout.simple_expandable_list_item_1,
            new String[] { NAME, IS_EVEN },
            new int[] { android.R.id.text1, android.R.id.text2 },
            childData,
            android.R.layout.simple_expandable_list_item_2,
            new String[] { NAME, IS_EVEN },
            new int[] { android.R.id.text1, android.R.id.text2 }
            );
    setListAdapter(mAdapter);

    }

}

关于android - 需要 Greendroid GDExpandableListActivity 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572993/

相关文章:

onCreate 的 java.lang.NoSuchMethodException

android - 蓝牙或 wifi 流 (spp) 是否会丢失字节或损坏字节?

javascript - 将 JSON 提要(WP 提要)解析为 React Native 提要页面

android - 如何在可扩展 ListView 中添加列表项?

java - 导入 GreenDroid 时出现问题

android - configChanges ="orientation"不会在 Galaxy Nexus 上触发

java - 可扩展 ListView 中不同组的不同布局

android - 可展开的 ListView onGroupExpanded 和 onGroupCollapsed

android - 如何将 GreenDroid 添加到现有的 Android Studio 项目中?

android - GreenDroid ActionBar 方法名称冲突