我需要帮助,请有人帮我解决开关和外壳...
我在操作栏 item1、item2、item3 中有 3 个项目,并且我有 3 个活动 item1Activity.java、item2Activity、item2Activity.. 我想在选择项目时从菜单中调用这些活动..
public class MainActivity extends Activity {
/** An array of strings to populate dropdown list */
String[] actions = new String[] {
"Item1",
"Item2",
"Item3"
};
protected int position;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Create an array adapter to populate dropdownlist */
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, actions);
/** Enabling dropdown list navigation for the action bar */
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
/** Defining Navigation listener */
ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
switch (itemPosition) {
case 1:
Intent i = new Intent();
i.setClass(getApplicationContext(), Item1Activity.class);
startActivity(i);
return true;
case 2:
Intent i = new Intent();
i.setClass(getApplicationContext(), Item2Activity.class);
startActivity(i);
return true;
}
}
};
/** Setting dropdown items and item navigation listener for the actionbar */
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
}
}