Post Reply Subscribe to Thread Email Thread

Nav drawer reloads fragments each time it closes...

13th February 2014, 03:12 AM |#1  
OP Junior Member
Thanks Meter: 0
8 posts
Join Date:Joined: Jun 2013
I have a navigationDrawer that I am implementing for the first time, and each time I close the navigationDrawer without selecting an option in the listVIew it reloads a fragment.... I need help on how to reorganize my code so the drawer can close without reloading the fragments each time.

public class MainDraw extends FragmentActivity {
    final String[] data ={"Statistics","Discover","three"};
    final String[] fragments ={
    protected void onCreate(Bundle savedInstanceState) {

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

        final DrawerLayout drawer = (DrawerLayout)findViewById(;

        final ListView navList = (ListView) findViewById(;

        navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){

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

                    public void onDrawerClosed(View drawerView){
                        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
                        tx.replace(, Fragment.instantiate(MainDraw.this, fragments[pos]));





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


Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes