有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android:在不滑动的情况下更改ViewPager中的片段

我是初学者,所以在回答时请记住这一点

我刚刚实现了在两个不同片段之间滑动的功能。我遵循了这个教程:https://developer.安卓.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的搜索结果。 感谢您的帮助


共 (1) 个答案

  1. # 1 楼答案

    尝试使用viewPager。第(1)项;在你的按钮里点击监听器。确保在显示片段之前正确加载片段