android - 菜单gui难度

时间:2011-08-21 04:09:35

标签: android user-interface menu

当我使用我在这个类中定义的简单数组时,它工作正常,但是当我从strings.xml调用这个字符串数组时,它似乎永远不会工作....任何建议?我正在尝试制作一个列出所有章节标题的菜单

我做错了什么???

我对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));

    }

1 个答案:

答案 0 :(得分: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));
    }