Reputation: 246
I have an app that implement sliding menu from jfeinstein10. all my apps are not using fragment. so i change the list of fragment into list activity. when i click that list, it start another activity. But the sliding menu didn't close. it still in slide mode. i just want to "when i click item in list activity, it closes slide menu and start an activity." i have tried like this.
@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
Fragment newContent = null;
Fragment Intent = null;
switch (position) {
case 0:
Intent intent2 = new Intent();
intent2.setClass(getActivity(), tab.class);
intent2.putExtra("index", position);
startActivity(intent2);
break;
case 1:
Intent intent = new Intent();
intent.setClass(getActivity(), about.class);
intent.putExtra("index", position);
startActivity(intent);
break;
case 2:
Intent intent3 = new Intent();
intent3.setClass(getActivity(), tab1.class);
intent3.putExtra("index", position);
startActivity(intent3);
break;
case 3:
Intent intent4 = new Intent();
intent4.setClass(getActivity(), latin.class);
intent4.putExtra("index", position);
startActivity(intent4);
break;
case 4:
newContent = new ColorFragment(android.R.color.black);
break;
}
if (newContent != null)
switchFragment(newContent);
if (Intent != null)
switchFragment(Intent);
}
I know its dumb to use Fragment Intent = null;
And If (Intent != Null) switchFragment(Intent);
. I know its just for fragment only, but is there another way to switch it like that? So that when click, the slide menu closed and start the activity. Thanks
Upvotes: 0
Views: 1421
Reputation: 73
If you are using a ListFragment and your onListItemClick placed there. you can use:
((MainActivity) this.getActivity()).menu.toggle();
or:
((MainActivity) this.getActivity()).getMenu().toggle();
Upvotes: 0
Reputation:
Try to use this kind of code for toggling the state of the Sliding menu
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toggle();
}
}, 1000);
}
Upvotes: 1