Use backstack with ViewPager

后端 未结 5 1450
栀梦
栀梦 2021-01-02 09:44

I am using a ViewPager to implement swiping in my android app. However, I would like the previous fragment to be shown when the user uses the back button instead of ending t

5条回答
  •  悲哀的现实
    2021-01-02 10:01

    Override the functionality of your Activity:

    public class Activity extends Activity
    {
        @Override
        public void onBackPressed()
        {
            // do stuff
            myFragment.onBackPressed();
        }
    }
    
    public class Fragment extends Fragment
    {
    
        public void onBackPressed()
        {
            // do stuff
        }
    }
    

提交回复
热议问题