English 中文(简体)
• 在开关案件中使用str子。
原标题:Using strings in a switch case for a menu?

我为目前的一个论坛做了准备,我补充说了一个有利可图的章节,你可以增加你的有利部分,以便迅速进入。 我的菜单是一份列有不同章节的清单的,因此,我的确要开一个开关,来决定某一菜单项目何时会做些什么。 我通过这样做了解到,你可以用插头处理开关案件,因此,我的问题是,我怎么能够推断一下什么纽特人受到压制,以及为什么有人受到压制?

This is my code for the menu:

public class Menu extends ListActivity{

String[] classes = {"Home", "Gaming", "Microsoft Consoles", 
        "Sony Consoles", "Other Platforms", "Tech Center", "General"};

@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, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    switch (classes) {
    case "Home":

    break; 
    case "Gaming".hashCode(): 

    break; 
    }   
}
}

我之所以出现错误,是因为班级是强硬的,而且我可以不使用开关的班子,这样是能够这样做的还是另一种做法?

最佳回答
问题回答

更好的解决办法:

一等:

public enum Tabs 
{
 Home, 
 Gaming, 
 Microsoft_Consoles, 
 Sony_Consoles, 
 Other_Platforms, 
 Tech_Center, 
 General
}

在另一类:

 switch (classes)
 {
   case Home:

   break;
 ...
 }

@override the toString() category of the enum Tabs to do it nice .





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签