【发布时间】:2017-08-07 12:06:52
【问题描述】:
我是初学者,所以请在回答时记住这一点。
我刚刚实现了在 2 个不同片段之间滑动的功能。我按照本教程进行操作:https://developer.android.com/training/animation/screen-slide.html
它工作正常。但我也想通过单击按钮而不是滑动屏幕来提供在这两个片段之间切换的选项。
public void timerWindowButton(View v) {
//timerWindow() executes the newInstance() method of the fragment
Fragment fragment = timerWindow();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
//here i try to replace the content of the pager, but the result is
//an empty screen
ft.replace(R.id.pager, fragment);
ft.commit();
我试图用谷歌搜索我的问题,但我最终得到了关于如何首先实现 ViewPager 的搜索结果。 任何帮助表示赞赏!
【问题讨论】:
-
尝试使用 viewPager.setCurrentItem(1);在您的按钮单击侦听器内。确保在显示之前正确加载片段。
-
谢谢,效果很好!
-
太棒了!!!快乐编码..
-
您想将其发布为“真实”答案吗?这对您和未来的读者来说不是更好吗?
标签: java android android-fragments android-activity android-viewpager