ArrayAdapter
にデータを入力するために元々使用していた文字列のセットがありますSpinner
。の代わりに、Spinner
を使用したいと思いますBaseExpandableListAdapter
。文字列配列値のセットをString
オブジェクトに取り込む方法はありますか?
これが私の文字列配列です
<string-array name="component2_color">
<item>Blueberry</item>
<item>Chocolate</item>
<item>Dark Chocolate</item>
<item>Lemon</item>
<item>Lime</item>
<item>Orange</item>
<item>Strawberry</item>
<item>Raspberry</item>
<item>Grape</item>
<item>Vanilla</item>
<item>Butterscotch</item>
</string-array>
そして、これは私がApiDemosから取得したコードの抜粋であり、拡張可能なリストのグループと子にデータを設定する方法を示しています。
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
private String[][] children = {
{ "Arnold", "Barry", "Chuck", "David" },
{ "Ace", "Bandit", "Cha-Cha", "Deuce" },
{ "Fluffy", "Snuggles" },
{ "Goldy", "Bubbles" }
};
String
子供たちに4つの異なる文字列配列を使用してもらいたい。これについて私が行くことができる方法はありますか?どうやって始めたらいいのかよくわかりません。
編集:これを試しましたが、リソースが見つからないという例外が発生します。
private String[] groups = {UserMessage.this.getString(R.array.message_groups)};
private String[][] children = {{UserMessage.this.getString(R.array.message_group_1)},
{UserMessage.this.getString(R.array.message_group_2)},
{UserMessage.this.getString(R.array.message_group_3)},
{UserMessage.this.getString(R.array.message_group_4)}
};