简体   繁体   English

如何在Android应用程序开发中使用列表数组菜单

[英]How to use a list array menu in android app development

I quite new to android app dev, and I am trying to use a list array to create a menu, I have done this but only the first item will work. 我对android app dev相当陌生,我试图使用列表数组来创建菜单,我已经做到了,但是只有第一个项目可以使用。 This is the code I have used to create the menu: 这是我用来创建菜单的代码:

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Menu extends ListActivity {

String menuItems[] = { "MainActivity","BMI Key", "BMI Chart", "BMI Calculator"};

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

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String menu = menuItems[position];
    try {
    Class classCR = Class.forName("rolston.c.bmi.calculator." + menu);
    Intent crIntent = new Intent(Menu.this, classCR);
    startActivity(crIntent);
        }catch(ClassNotFoundException a){
            a.printStackTrace();
        }
}

} }

My main question is how to get "BMI Key" etc to open up a specific xml file? 我的主要问题是如何获取“ BMI密钥”等来打开特定的xml文件?

Any help would be much appreciated. 任何帮助将非常感激。

I found out that I had to name the string correctly in the array, then add the corresponding java file to the android manifest. 我发现我必须在数组中正确命名字符串,然后将相应的java文件添加到android清单中。

Not as difficult as I thought. 没有我想的那么难。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM