// Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); }
/** * Swaps fragments in the main content view */ private void selectItem(intposition) { // Create a new fragment and specify the planet to show based on position Fragment fragment = newPullToRefreshFragment(); // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment) .commit(); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
@Override public void setTitle(CharSequence title) { super.setTitle(title); // getActionBar().setTitle(title); }
@Override publicbooleanonCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.navigation, menu); returntrue; }
@Override publicbooleanonOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId();
//noinspection SimplifiableIfStatement if (id == R.id.action_settings) { returntrue; }
returnsuper.onOptionsItemSelected(item); }
@SuppressWarnings("StatementWithEmptyBody") @Override publicbooleanonNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId();
if (id == R.id.nav_camera) { // Handle the camera action } elseif (id == R.id.nav_gallery) {