Skip to content Skip to sidebar Skip to footer

DrawerLayout On Click Disabled After First Event

I'm trying to implement a drawer layout in my app. I follow the tutorial on android developer site and all goes fine. I have only a 'little' problem: I lunch the app, open the draw

Solution 1:

Take a look at my code:

private class DrawerItemClickListener implements ListView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView parent, View view, int position, long id) {
            selectItem(position);
        }
    }

private void selectItem(int position) {

        switch (position) {

            case 0:

                fragmentManager.beginTransaction()
                        .replace(R.id.content_frame, new MainActivityFragment())
                        .commit();
                break;

            case 1:

                fragmentManager.beginTransaction()
                        .replace(R.id.content_frame, new DbListViewFragment())
                        .commit();
                break;

            case 2:

                fragmentManager.beginTransaction()
                        .replace(R.id.content_frame, new StatisticsFragment())
                        .commit();
                break;

            case 3:

                fragmentManager.beginTransaction()
                        .replace(R.id.content_frame, new CalculatorFragment(), "calculator")
                        .commit();
                break;

        }

I am using a switch-case. position 0 is the very first item in my ListView inside the drawer.


Solution 2:

The problem is that you are using

                                   FragmentTransaction.replace(r.Id.drawer_layout,fragment).

don't attach a fragment directly to the drawerlayout element , try to add a framelayout as your main content container then attach the fragment to this framelayou. Your xml content should look like this sudo one

<drawerlayout>
    <framelayout Id:fragment_holder/> //attach fragment        to this view
        <ListView/>  // your drawer ListView.
<drawerlayout/>

Post a Comment for "DrawerLayout On Click Disabled After First Event"