fragment嵌套fragment类,然后调用其中方法,处理请求。

来源:互联网 发布:小米5x和小米max2知乎 编辑:程序博客网 时间:2024/06/04 18:45
跳转fragment时使用:
        getActivity().getSupportFragmentManager().beginTransaction()                .add(R.id.right_voucher_fragment_container, friendFragment,"voucher_friend_list")                .commit();

其中R.id.right_voucher_fragment_container为你自己的activity或者Fragment中的FramLayout
    <!-- java 代码中添加的Fragment所在的容器 -->    <FrameLayout        android:id="@+id/right_voucher_fragment_container"        android:layout_width="match_parent"        android:layout_height="match_parent"        tools:context="com.fujitsu.fragment.RightVoucherFragment"        tools:ignore="MergeRootFrame"        ></FrameLayout>


VoucherFriendListFragment friendFragment = new VoucherFriendListFragment();

其中friendFragment为你要跳转到的fragment,如上。
public Handler baseHandler = new Handler() {    public void handleMessage (Message msg) {//此方法在ui线程运行        switch(msg.what) {            case 0x01:                clearTextColor();                select.setTextColor(Color.parseColor("#000000"));                break;            case 0x02:                clearTextColor();                payby.setTextColor(Color.parseColor("#000000"));                break;            case 0x03:                clearTextColor();                confirm.setTextColor(Color.parseColor("#000000"));                break;            case 0x04:                clearTextColor();                complete.setTextColor(Color.parseColor("#000000"));                break;        }    }};

你自己的fragment可以做一些界面改变。

然后,你就可以为所欲为了!

VoucherMainFragment mainFragment = (VoucherMainFragment) manager.findFragmentByTag("voucher_main");mainFragment.baseHandler.sendEmptyMessage(0x01);

其中最主要的是获取上级fragment!

1 0
原创粉丝点击