【问题标题】:Equivalent of FragmentTransaction attach / detach for Android 3.0相当于 Android 3.0 的 FragmentTransaction 附加/分离
【发布时间】:2011-11-17 14:30:46
【问题描述】:

在 Android 3.2 上,有 2 个新方法:FragmentTransaction 的附加和分离。 但是,这些功能不适用于 Android 3.0 和 3.1。 有没有办法绕过它?

Tkx

【问题讨论】:

    标签: android android-3.0-honeycomb android-fragments fragment


    【解决方案1】:

    如果您打算进行分段事务,只需使用文档齐全的 3.0 和 3.1 API 版本即可。您应该检查FragmentTransaction 类中的addremovereplace

    有关实际示例,请查看Performing Fragment Transactions,并阅读整个Fragments 框架主题。这是我所知道的最好的资源之一。

    另外,请查看以下教程: The Android 3.0 Fragments APIHow to use the Fragment class in the Android Honeycomb SDK.

    不管怎样,这里是一个代码剪辑:

    Fragment f = new TestFragment();
    
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    // Replaces an existing fragment with the newly created one
    ft.replace(R.id.the_frag, f);
    // Any transition you prefer
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    // Add it to the stack so the transition will be remembered and could be reversed
    ft.addToBackStack(null);
    ft.commit();
    

    如果你只是想detachattach 一个片段,这可以通过上面提到的添加和删除来完成,并确保在添加时膨胀它的内容视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2012-06-03
      • 2014-08-06
      • 2023-03-16
      • 2011-12-16
      • 1970-01-01
      相关资源
      最近更新 更多