Team Win Recovery Project for Tornado 348

more

PhotoMath: A Math Beginner’s Dream App

more

Leaked Galaxy S6 Apps Hit the Forums

more

Fix Untinted Recent Panels on Lollipop

more
Post Reply

Exclamation Sliding menu problem

OP hastalafiesta

19th March 2014, 07:47 PM   |  #1  
OP Senior Member
Flag Italy
Thanks Meter: 909
 
674 posts
Join Date:Joined: Nov 2012
Donate to Me
More
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.

MAINACTIVITY

Code:
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 android.R.id.home:
            this.slidingMenu.toggle();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
            }
	}
SLIDING MENU FRAGMENT

Code:
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(R.id.slidingmenu_view);
        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(R.id.frame_container, 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;

    }}

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

Advanced Search
Display Modes