I'm making an app for a forum currently, and I'm adding a favorites section where you can add your favorite sections for quick access. I have a menu set up that has a list of the different sections, so what I did was make a switch case to decide what to do when a certain menu item is pressed, in this case the section. Through doing this I learned that you can't use strings with a switch case, so my question is how could I decifer which button was pressed and do an action according to which one was pressed?
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;
}
}
}
I get an error because classes is a String[], and I can't use that with a switch case, so is there a way to do that, or an alternative?