使用字符串数组填充Android中的列表视图

时间:2011-01-28 00:51:08

标签: android android-listview

我是Android和Java开发的新手。我正在尝试使用字符串数组填充列表视图。我继续收到错误 - 构造函数ArrayAdapter(QuizMenuActivity,int,String [])未定义

感谢任何帮助。代码发布在下面。

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);     
    ListView menuList=(ListView) findViewById(R.id.ListView_Menu);
    String [] items = new String[] { getResources().getString(R.string.menu_item_Play),
            getResources().getString(R.string.menu_item_scores),
            getResources().getString(R.string.menu_item_settings),
            getResources().getString(R.string.menu_item_help)};
    ArrayAdapter <string> adapt = new ArrayAdapter<string> (this, 
        R.layout.menu_item, items);
    menuList.setAdapter(adapt)

3 个答案:

答案 0 :(得分:1)

这可能有效:

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);   

    String [] items = new String[] { getResources().getString(R.string.menu_item_Play),
            getResources().getString(R.string.menu_item_scores),
            getResources().getString(R.string.menu_item_settings),
            getResources().getString(R.string.menu_item_help)};

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

答案 1 :(得分:1)

为什么不使用Map而不是使用Array&gt;用地图填充地图将地图添加到数组,然后将数组转换为String [] ..

答案 2 :(得分:-2)

this.setListAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1,R.array.DateEven));