首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要Greendroid GDExpandableListActivity示例

需要Greendroid GDExpandableListActivity示例
EN

Stack Overflow用户
提问于 2013-03-22 22:35:11
回答 1查看 120关注 0票数 1

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-23 16:04:32

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

代码语言:javascript
复制
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);

    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15572993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档