Der ganze activity code füge ich dir mal unten hin und brauchst du den adapter auch?
Java
// Declare Variable
DrawerLayout mDrawerLayout;
ListView mDrawerList;
ActionBarDrawerToggle mDrawerToggle;
MenuListAdapter mMenuAdapter;
String[] title;
//String[] subtitle;
int[] icon;
Fragment about = new About();
Fragment maps = new Maps();
Fragment home1 = new Home();
Fragment weather = new Weather();
Fragment catch_session = new Catch_session();
Fragment catch_book = new Catch_book();
Fragment tips_tricks = new Tips();
Fragment test = new Test();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_main);
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
// Generate title
title = new String[] { "Startseite", "Angelpl\u00E4tze", "Wetter", "Schonzeiten", "Fangbuch", "Tipps \u0026 Tricks", "\u00DCber", "Test1"}; //, "Einstellungen", "Tipps \u0026 Tricks"
// Generate subtitle
//subtitle = new String[] { "","Wer hat gemacht?", "Ihre Einstellungen"};
// Generate icon
icon = new int[] {R.drawable.action_home, R.drawable.action_location, R.drawable.collections_cloud, R.drawable.action_catchsessions,
R.drawable.action_catchbook, R.drawable.action_help, R.drawable.action_about, R.drawable.action_about}; //, R.drawable.action_settings
// Locate DrawerLayout in drawer_main.xml
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// Locate ListView in drawer_main.xml
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set a custom shadow that overlays the main content when the drawer
// opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
// Pass results to MenuListAdapter Class
mMenuAdapter = new MenuListAdapter(this, title, icon); //subtitle,
// Set the MenuListAdapter to the ListView
mDrawerList.setAdapter(mMenuAdapter);
// Capture button clicks on side menu
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
// TODO Auto-generated method stub
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
// TODO Auto-generated method stub
super.onDrawerOpened(drawerView);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
}
return super.onOptionsItemSelected(item);
}
// The click listener for ListView in the navigation drawer
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
private long ID;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (ID == id) {
selectItem(position);
}
ID = id;
}
}
private void selectItem(int position) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
// Locate Position
switch (position) {
case 0:
ft.replace(R.id.content_frame, home1);
break;
case 1:
ft.replace(R.id.content_frame, maps);
break;
case 2:
ft.replace(R.id.content_frame, weather);
break;
case 3:
ft.replace(R.id.content_frame, catch_session);
break;
case 4:
ft.replace(R.id.content_frame, catch_book);
break;
case 5:
ft.replace(R.id.content_frame, tips_tricks);
break;
case 6:
ft.replace(R.id.content_frame, about);
break;
case 7:
ft.replace(R.id.content_frame, test);
/*case 7:
ft.replace(R.id.content_frame, settings);
break;*/
}
ft.commit();
mDrawerList.setItemChecked(position, true);
// Close drawer
mDrawerLayout.closeDrawer(mDrawerList);
}
Alles anzeigen