-
我试图向我的应用程序添加一个选项卡主机,但我无法弄清楚为什么显示此错误"无法解析构造函数意图",这是我的活动代码:
public class SixthFragment extends Fragment { public static final String TAG = "sixth"; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.sixthfragment, container, false); TabHost tabHost = (TabHost) view.findViewById(R.id.tabHost); TabHost.TabSpec tab1 = tabHost.newTabSpec("First Tab"); TabHost.TabSpec tab2 = tabHost.newTabSpec("Second Tab"); TabHost.TabSpec tab3 = tabHost.newTabSpec("Third tab"); // Set the Tab name and Activity // that will be opened when particular Tab will be selected tab1.setIndicator("Tab1"); tab1.setContent(new Intent(this,MainActivity.class)); tab2.setIndicator("Tab2"); tab2.setContent(new Intent(this,Tab2Activity.class)); tab3.setIndicator("Tab3"); tab3.setContent(new Intent(this,Tab3Activity.class)); /** Add the tabs to the TabHost to display. */ tabHost.addTab(tab1); tabHost.addTab(tab2); tabHost.addTab(tab3); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } }
一些帮助将不胜感激,感谢您的时间。
您尝试使用的 Intent
构造函数的第一个参数需要Context
。 Fragment
不是Context
.使用 getActivity()
而不是 this
。