【问题标题】:When click button inside fragment I want to go to another fragment in the parent TabLayout单击片段内的按钮时,我想转到父 TabLayout 中的另一个片段
【发布时间】:2016-10-04 15:03:47
【问题描述】:

我有一个 MainActivity,包含有两个片段 FA、FB 的 TabLayout

具有另一个 Tablayout 的第一个片段 FA 包含 2 个片段 FAA、FAB

我在 FAA 中有一个按钮,当我点击它时,它会将我发送到已经在父 TabLayout 内的 FB

我尝试了很多解决方案,但都没有帮助,有什么建议吗?

    @OnClick(R.id.frag_timeline_fab_faa)
public void goToFBFromFAA(View view) {

    // Code shoud be here
}

【问题讨论】:

    标签: android android-fragments material-design android-tablayout


    【解决方案1】:

    这样做的方法是通过接口。Here is a similar question I found

    在 FAA 片段中:

    public interface OnFragmentInteractionListener {
        void onFragmentInteraction(Param param);
    }
    

    然后在你的父片段中你需要实现那个接口:

    public class FA extends Fragment implements 
            FAA.OnFragmentInteractionListener {
        @Override
        public void onFragmentInteraction(Param param) {
        //Your code here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多