片段的愚蠢bug.back按钮

时间:2012-03-29 07:40:53

标签: android fragment

片段让我感到沮丧!有三个片段,片段[A] - > [B] - > [C]。使用replace(id,fragment)来改变当前视图`,

First.I start page A(add to back),then B(dont add to back),
     then C(add to back).

Second.In Fragment C,press back button.The FragmentA is showing.

Third.when I click somewhere in FragmentA .Bug has been happened,
     indeed I could click view in FragmentB(this Fragment is not show!).

My Fragment swap方法

 private static void replacefrag(String tag, FragmentTransaction ft, Fragment target, Bundle b, Boolean allowloss, Boolean addtoback) {
        int resId = R.id.mytabcontent;
        if (b != null) {
            b.putAll(b);
            target.setArguments(b);
        }
        if (addtoback) {
            ft.addToBackStack(tag);

        }
        if (tag != null) {
            ft.replace(resId, target, tag);
        } else {
            ft.replace(resId, target);
        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        if (allowloss) {
            ft.commitAllowingStateLoss();
        } else {
            ft.commit();
        }
    }

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <FrameLayout
            android:id="@+id/mytabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/yellow"
            />
</LinearLayout>

fraga.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:background="@color/green_back" android:layout_height="fill_parent">
    <Button
            android:id="@+id/fraga_btn"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="AAAAAAAAAAA"
            />
</RelativeLayout>

fragb.xml,fragc.xml与fraga.xml类似 有没有人有同样的问题?大虫子?还是我错过了什么? 我写了一个演示项目来展示这些问题。你可以download source here

0 个答案:

没有答案