【发布时间】:2015-05-13 05:19:36
【问题描述】:
您好,我是 Android 新手,在我的项目中使用 PageViewer 来显示 Tab 滑动和其他类似的东西
我使用了 4 个标签,并为每个标签使用了片段 现在,其中 1 个选项卡有一个列表,其中的按钮可以在同一个选项卡上调用另一个片段,即我需要替换同一选项卡上的片段。
我遇到了这个堆栈问题,如链接中所示,该链接说使用广播侦听器来调用片段。我在 Fragment 类中使用了它。
http://stackoverflow.com/questions/22265378/how-to-call-a-fragment-from-baseadapter-class-android/22265433#22265433
我在需要调用框架布局时遇到错误
因为它使用android id,如果我将它更改为@+id,那么它会给出错误
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" >
</FrameLayout>
我在我的 Fragment 中使用它来用另一个 Fragment 替换一个 Fragment
BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Recived",
Toast.LENGTH_LONG).show();
FieldVisitFragment fieldvisitFragment = new FieldVisitFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(need to know what id to pass, fieldvisitFragment);
fragmentTransaction.commit();
}
};
我的显示选项卡布局如下所示,我正在使用 android.support.v4 库作为 Fragment 。请帮忙。
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="900dp"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" >
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TabWidget>
</LinearLayout>
</TabHost>
【问题讨论】:
-
试试
fragmentTransaction.replace(android.R.id.tabcontent, fieldvisitFragment); -
替换了它......但是现在如果我点击什么都没有发生......我如何在 Manifest 文件中注册这个接收器
标签: android android-fragments tabs transactions android-viewpager