これが私が最近行ったことExpandableListView
です。かなり簡単です。
これまでにAndroidで見た中で最大のコンストラクターの1つがあります。
を使用してレイアウトを作成しますExpandableListView
。
<LinearLayout>
<ExpandableListView>
<!-- Set the properties, if you need to see them, let me know. -->
</ExpandableListView>
</LinearLayout>
次に、いくつかのビューでレイアウトを使用します。
public void onCreate() {
ExpandableListView example = findViewById(/* The id of the expandable list view */);
example.setAdapter(
new SimpleExpandableListAdapter(
/* the context */,
/* the map of parents/groups */,
/* the layout to map the parents/groups to */,
/* the key to search for in the parents/groups map */,
/* the id of the textview inside the layout to map the parent/group to */,
/* the map of children */,
/* the layout to map the children to */,
/* the key to search for in the children map */,
/* the id of the textview inside the layout to map the children to */)
)
}
他にも利用可能なアダプターがありますが、これが最も基本的なアダプターです。
基本的には、開発者のWebサイトを見てください。この例も多少役に立ちましたが、開発者のWebサイトは大いに役立ちます。
ご不明な点がございましたら、お気軽にお問い合わせください。
ファローアップ
彼はcreateGroupList()を置きました。これは彼がコメントした関数のようです。これは正確に何をしているのですか?
彼は基本的にその関数List
でofを作成しHashMaps
、作成されたオブジェクトを返します。はい、あなたはそのようなことをするべきです、それはあなたのコードを少しきれいに保つのを助けます。
また、これらのリストは本当に小さく表示されますが、とにかく大きくしますか?
TextView
子とグループを表示しているを変更します。View
それらのxml
レイアウトにパディングを追加します。を調整するだけdp
です。そして、あなたは増やすことができます、textSize
またはあなたは私が以下に示すようなものを加えることができstyle
ます。
<TextView
android:id="@+id/groupTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Medium"
android:paddingLeft="50dp"
android:paddingTop="25dp"
android:paddingBottom="25dp"/>
親グループをリストにしたいのですが、子グループをサブリストにしたくないので、テキストを追加できるテキストボックス(ネットから取得)にします。リストではなく子のテキストボックスを作成するにはどうすればよいですか。
あなたはおそらくAdapter
その状況のためにあなた自身を作成する必要があるでしょう。を拡張する必要がありますBaseExpandableListAdapter
。私は間違っている可能性があります、もっと簡単な方法があるかもしれません...しかし私は1つを知りません。
追加のフォローアップ
よく分からない。子リストに入力されるテキストは、次のコード行に入力されます:child.put( "Sub Item"、 "test")。「テスト」と表示されている場所に必要なテキストを配置できますが、すべての親リストの下に「テスト」が表示されます。
を返すcreateChildList
必要がありList<ArrayList<HashMap<String, String>>>
ます。
次のcreateChildList
ようになります。
private List<ArrayList<HashMap<String, String>>> createChildList(int maxValue) {
ArrayList<ArrayList<HashMap<String, String>>> groupList =
new ArrayList<ArrayList<HashMap<String, String>>>();
for (int i = 0; i <= maxValue; i++) {
ArrayList<HashMap<String, String>> childList =
new ArrayList<HashMap<String, String>>();
for (int j = 0; j <= maxValue; j++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("Sub Item", "test: " + String.valueOf(j));
childList.add(map);
}
groupList.add(childList);
}
return groupList;
}
それがうまくいくかどうか教えてください。