2012-01-07 7 views
0

ハードコードされた配列の代わりに配列リソースとしてExpandableListを実装する方法(既存のハードコードされた配列をXMLレイアウトに置き換える方法)については、正確にはわかりません。 R.array.xxx名前は動作しませんもちろんExpandableList配列リソースの実装に関する質問

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) 
    }; 

:ここに私のstrings.xmlがここ

<?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ファイルに変更するものです。ですから、R.javaに次のような文があるときに、どうすればこの問題を修正できますか?public static final int Cat Names = 0x7f040003 ;. これにはルールが必要ですが、まだ分かりません。

多くの例を参照すると、グループと子のレイアウトファイルと、おそらくメインレイアウトファイルが必要になると思います(私が必要な場合は、それらを実装する方法を知っていると思います)。これは正しいです?

ご協力いただきありがとうございます。

答えて

0

あなたは「人の名前」や他の文字列配列名から文字列配列

削除スペースの名前にスペースを持っています。

関連する問題