我正在使用以下代码创建一个菜单:
public class MainActivity extends ListActivity {
String classes[] = {"Add a fight to the card", "Add a fighter", "Edit a fighter"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
switch (position){
case 0:
Intent intent = new Intent(MainActivity.this, AddFight.class);
startActivity(intent);
case 1:
Intent intent2 = new Intent(MainActivity.this, AddFighter.class);
startActivity(intent2);
}
}
当我在我的列表中单击时case 0:
,intent incase 1:
被打开而不是case 0:
. 我该如何解决?