如何在按下或打开活动时éšè—滑动èœå•

时间:2013-04-11 20:56:21

标签: java android slidingmenu

https://github.com/jfeinstein10/SlidingMenu

我正在使用这个库,我想在打开一个新的activityæ—¶éšè—滑动èœå•ï¼Œè¿™æ ·å½“我按下时我ä¸å¸Œæœ›å‡ºçŽ°æ»‘动èœå•ã€‚

@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
    switch (position) {
    case 0:
        Intent intent = new Intent("android.intent.action.Home");
        getActivity().startActivity(intent);
        break;
   }
}

上é¢çš„代ç åœ¨æˆ‘çš„SherlockListFragment课程中,我想在开始新活动时éšè—滑动èœå•ã€‚

2 个答案:

答案 0 :(得分:12)

如果您已ç»æ‰©å±•äº†SlidingActivity,那么您åªéœ€è¦ï¼š -

toggle();

应该这样åšï¼š - )

答案 1 :(得分:3)

@Override
public void onListItemClick(ListView lv, View v, int position, long id) {   
    switch (position) {
    case 0:
        Intent intent = new Intent("android.intent.action.Home");
        getActivity().startActivity(intent);
        // Toggle the sliding menu
        ((YourHostActivity) getActivity()).getSlidingMenu().toggle();
        break;
   }
}

在托管滑动èœå•çš„活动中:

public onCreate(...) {
    // save the slidingmenu instance to a propery
    mSlidingMenu = new SlidingMenu(this);
}

// create a getter
public SlidingMenu getSlidingMenu() {
    return mSlidingMenu;
}