2011-08-21 47 views
0

當我使用一個簡單的數組,我在這個類中定義它時,它工作正常,但是當我從我的strings.xml調用這個字符串數組時,它似乎永遠不會工作....任何建議?我正在嘗試製作一個列出所有章節標題的菜單android-menu gui難度

我在做什麼錯?

我對java和android很新穎,所以請儘可能多地啞下去....謝謝!

import android.app.ListActivity; 
import android.content.res.Resources; 

import android.os.Bundle; 

import android.widget.ArrayAdapter; 

public class ChapterMenu extends ListActivity{ 

    Resources res= getResources(); 
    String [] chapterArray = res.getStringArray(R.array.chapters); 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setListAdapter(new ArrayAdapter<String>(ChapterMenu.this, android.R.layout.simple_list_item_1, chapterArray)); 

    } 
+0

您能查看使用調試或日誌chapterArray成功加載幷包含有效數據? –

回答

0
@Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 

     Resources res= getResources(); 
     String [] chapterArray = res.getStringArray(R.array.chapters); 

     setListAdapter(new ArrayAdapter<String>(ChapterMenu.this, android.R.layout.simple_list_item_1, chapterArray)); 
    }