Sliding menu problem (jfeinstein lib)

Hi guys I'm having problem with the jfeistein sliding menu. I have correctly imported it but i have only a problem. When I click on the "test" item it opens the related fragment but it doesn't autoclose the menu as it should.


public class MainActivity extends Activity { private SlidingMenu slidingMenu ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); slidingMenu = new SlidingMenu(this); slidingMenu.setMode(SlidingMenu.LEFT); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.setShadowWidthRes(R.dimen.slidingmenu_shadow_width); slidingMenu.setShadowDrawable(R.drawable.slidingmenu_shadow); slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset); slidingMenu.setFadeDegree(0.35f); slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); slidingMenu.setMenu(R.layout.slidingmenu); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public void onBackPressed() { if ( slidingMenu.isMenuShowing()) { slidingMenu.toggle(); } else { super.onBackPressed(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ( keyCode == KeyEvent.KEYCODE_MENU ) { slidingMenu.toggle(); return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case this.slidingMenu.toggle(); return true; default: return super.onOptionsItemSelected(item); } } }



public class SlidingMenuFragment extends Fragment implements ExpandableListView.OnChildClickListener { private SlidingMenu slidingMenu ; private ExpandableListView sectionListView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { List<Section> sectionList = createMenu(); View view = inflater.inflate(R.layout.slidingmenu_fragment, container, false); this.sectionListView = (ExpandableListView) view.findViewById(; this.sectionListView.setGroupIndicator(null);

SectionListAdapter sectionListAdapter = new SectionListAdapter(this.getActivity(), sectionList); this.sectionListView.setAdapter(sectionListAdapter); this.sectionListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return true; } }); this.sectionListView.setOnChildClickListener(this); int count = sectionListAdapter.getGroupCount(); for (int position = 0; position < count; position++) { this.sectionListView.expandGroup(position); } return view; }

private List<Section> createMenu() { List<Section> sectionList = new ArrayList<Section>();

Section oDemoSection = new Section("Demos"); oDemoSection.addSectionItem(101,"Test", "lol"); oDemoSection.addSectionItem(102, "Airport (AsyncTask)", "lol"); Section oGeneralSection = new Section("General"); oGeneralSection.addSectionItem(201, "Settings", "lol"); oGeneralSection.addSectionItem(202, "Rate this app", "lol"); oGeneralSection.addSectionItem(203, "Eula", "lol"); oGeneralSection.addSectionItem(204, "Quit", "lol"); sectionList.add(oDemoSection); sectionList.add(oGeneralSection); return sectionList; } public void toggle() { slidingMenu.toggle(); }

@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Fragment fragment=null; switch ((int)id) { case 101: FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(, new Net()).commit(); break; case 102: //TODO break; case 201: //TODO break; case 202: //TODO break; case 203: //TODO break; case 204: //TODO break; } return false;


Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by celia73
1 hour ago
Last post by boris48
13 minutes ago
Last post by roma81
4 hours ago
Last post by cdickens
5 hours ago
Last post by alexandra60
4 hours ago