0
我不是如何實現ExpandableList作爲陣列的資源,而不是硬編碼陣列(替換用XML佈局現有的硬編碼陣列)十分清楚。這是我的strings.xmlExpandableList陣列資源實現問題
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">adaptor_ExpandableList1</string>
<string name="expandable_list_sample_action">Sample action</string>
<string-array name="Groups">
<item>People Names</item>
<item>Dog Names</item>
<item>Cat Names</item>
<item>Fish Names</item>
</string-array>
<string-array name="People Names">
<item>Arnold</item>
<item>Barry</item>
<item>Chuck</item>
<item>David</item>
</string-array>
<string-array name="Dog Names">
<item>Ace</item>
<item>Bandit</item>
<item>Cha-Cha</item>
<item>Deuce</item>
</string-array>
<string-array name="Cat Names">
<item>Fluffy</item>
<item>Snuggles</item>
</string-array>
<string-array name="Fish Names">
<item>Goldy</item>
<item>Bubbles</item>
</string-array>
</resources>
這是我的Java文件中改爲:
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = getResources().getStringArray(R.array.Groups);
private String[][] children = {getResources().getStringArray(R.array.People Names),
getResources().getStringArray(R.array.Dog Names),
getResources().getStringArray(R.array.Cat Names),
getResources().getStringArray(R.array.Fish Names)
};
當然R.array.xxx名不起作用。那麼,如何在R.java中存在如下語句時糾正問題:public static final int Cat Names = 0x7f040003 ;. 必須有一個規則,但我還不知道。
翻閱無數的例子,我想我還需要有組和子佈局文件,也許主佈局文件(我想我知道如何實現他們,如果我需要)。它是否正確?
在此先感謝您的幫助!