ApiDemo の ExpandableList3.java がまさにそのデモ。

ExpandableListActivity を継承した Activity を作ります。
- import android.app.ExpandableListActivity;
- import android.os.Bundle;
- import android.widget.ExpandableListAdapter;
- import android.widget.SimpleExpandableListAdapter;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class ExpandableListTest extends ExpandableListActivity {
- private static final String NAME = "NAME";
- private static final String IS_EVEN = "IS_EVEN";
- private ExpandableListAdapter mAdapter;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // 親要素
- 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>();
- curGroupMap.put(NAME, "Group " + i);
- groupData.add(curGroupMap);
- // 子要素の値を設定
- List<Map<String, String>> children = new ArrayList<Map<String, String>>();
- for (int j = 0; j < 15; j++) {
- Map<String, String> curChildMap = new HashMap<String, String>();
- curChildMap.put(NAME, "Child " + j);
- curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
- children.add(curChildMap);
- }
- childData.add(children);
- }
- // adapter 設定
- mAdapter = new SimpleExpandableListAdapter(
- this,
- // 親要素
- groupData,
- // 親要素のレイアウト
- android.R.layout.simple_expandable_list_item_1,
- // 親要素のListで、表示するMapのKey
- new String[] { NAME },
- // 親要素レイアウト内での文字を表示する TextView の ID
- new int[] { android.R.id.text1 },
- // 子要素
- childData,
- // 子要素のレイアウト
- android.R.layout.simple_expandable_list_item_2,
- // 子要素のListで、表示するMapのKey
- new String[] { NAME, IS_EVEN },
- // 子要素レイアウト内での文字を表示する TextView の ID
- new int[] { android.R.id.text1, android.R.id.text2 }
- );
- setListAdapter(mAdapter);
- }
- }
hi, got confuse how to start it,can you
返信削除send me the source code, i really need this, thnk u
id:edwardpark.1997@gmail.com
はじめまして、きがんと申します。
返信削除ExpandableListActivity を使用しようとしたのですが、
このアクティビティ自身が起動しなくて困っています。
Android1.5では動くのにAndroid1.6では関数の中にすら入る事ができませんでした。
何か、Android1.6で同じような動きをするようなものって分かりませんでしょうか?
k_iwata さん
返信削除はじめまして。
よく状況がつかめないのですが、どの関数のことですか?
ExpandableListActivity は最新のOSでも使えますよ。
ご回答ありがとうございます。
返信削除自分がやろうとしていた事が親レイアウトをXMLで指定して作業を行うというものだったので、
SimpleExpandableListAdapter で対応取れていないものだったから落ちていたようでした。