java在通过片段显示活动时出错
我试图显示一个我的网页碎片,但它给我一个错误
我创建了一个名为FragmentContacts的单独类文件。java,在这里我展示了activity_联系人的布局。xml
Java代码片段:
package me.example.app;
import 安卓.os.Bundle;
import 安卓.support.v4.app.FragmentActivity;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
public class FragmentContacts extends FragmentActivity {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
View view = inflater.inflate(R.layout.activity_contacts, container, false);
return view;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// setUserVisibleHint(true);
}
}
片段代码:
public Fragment getItem(int arg0) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
//Fragment fragment = new DummySectionFragment();
//Bundle args = new Bundle();
//args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
//fragment.setArguments(args);
//return fragment;
switch (arg0) {
// Open FragmentTab1.java Error on return fragmenttab1
case 0:
FragmentContacts fragmenttab1 = new FragmentContacts();
return fragmenttab1;
return null;
}
# 1 楼答案
决心
这就是我所做的: 1) 我为每个选项卡分别创建了片段类。 2) 然后我使用了这个案例,以便在各自的选项卡中显示每个活动
(很抱歉我没有专业术语。)
解决方案: