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:
privateclassDrawerItemClickListenerimplementsListView.OnItemClickListener {
@OverridepublicvoidonItemClick(AdapterView parent, View view, int position, long id) {
selectItem(position);
}
}
privatevoidselectItem(int position) {
switch (position) {
case0:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newMainActivityFragment())
.commit();
break;
case1:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newDbListViewFragment())
.commit();
break;
case2:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newStatisticsFragment())
.commit();
break;
case3:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newCalculatorFragment(), "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>
<framelayoutId:fragment_holder/>//attach fragment to this view<ListView/>// your drawer ListView.<drawerlayout/>
Post a Comment for "Drawerlayout On Click Disabled After First Event"