Android ViewPager片段,未连接?
我的ViewPager有问题。它不会显示任何我预先定义的片段,它只是显示一个黑屏。从片段内部调用onCreateView方法Android ViewPager片段,未连接?,android,android-viewpager,Android,Android Viewpager,我的ViewPager有问题。它不会显示任何我预先定义的片段,它只是显示一个黑屏。从片段内部调用onCreateView方法 public class TestViewPager extends FragmentActivity { @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.test_view_pag
public class TestViewPager extends FragmentActivity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.test_view_pager);
}
}
public class TestFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View fragmentView = inflater.inflate(R.layout.entry_layout, container, false);
return fragmentView;
}
}
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
class="com.test.TestFragment"
android:id="@+id/embedded1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
class="com.test.AnotherTestfragment"
android:id="@+id/embedded2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.view.ViewPager>
公共类TestViewPager扩展了碎片活动{
@凌驾
创建公共void(Bundle){
super.onCreate(bundle);
setContentView(R.layout.test\u view\u pager);
}
}
公共类TestFragment扩展了片段{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图碎片视图=充气机。充气(右布局。入口布局,容器,假);
返回碎片视图;
}
}
使用ViewPager,您必须实现PagerAdapter并从中提供片段。您不能从XML定义要在ViewPager中显示的视图/片段,因为它根本不会绘制它们
编辑:因为要显示片段,所以必须使用FragmentPagerAdapter