0

I have implemented a navigation drawer with fragments but I seemed to have messed it up a little bit. Currently whenever the drawer closes without an listitem being selected it re loads a fragment.

My MainDrawer class which holds the fragments is:

public class MainDraw extends FragmentActivity {
    final String[] data ={"Statistics","Discover","three"};
    final String[] fragments ={
            "com.beerportfolio.beerportfoliopro.StatisticsPage",
            "com.beerportfolio.beerportfoliopro.Discover",
            "com.beerportfolio.beerportfoliopro.FragmentThree"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, data);

        final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);


        final ListView navList = (ListView) findViewById(R.id.drawer);
        navList.setAdapter(adapter);

        navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
                drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){



                    @Override
                    public void onDrawerClosed(View drawerView){
                        super.onDrawerClosed(drawerView);
                        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
                        tx.replace(R.id.main, Fragment.instantiate(MainDraw.this, fragments[pos]));
                        tx.commit();


                    }

                });

                drawer.closeDrawer(navList);

            }
        });

        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
        tx.replace(R.id.main,Fragment.instantiate(MainDraw.this, fragments[0]));
        tx.commit();

    }


}
Mike
  • 6,751
  • 23
  • 75
  • 132

1 Answers1

1

Follow the link, you may find out where is the problem in your code.

Android Sliding Menu using Navigation Drawer

Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
  • awesome, changed up my code a bit as a result. Looks great but the onCLicks for the nav drawer to load the new fragments does not seem to be working: http://stackoverflow.com/questions/21760094/onclick-for-navigationdrawer-not-loading-new-fragments – Mike Feb 13 '14 at 16:39