我想在我的项目中使用ViewPager作为片段。我片段的名称是'ViewP',它实现了ActionBar.TabListener。 但是,虽然片段事务我得到错误
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
Fragment fragment = new ViewP();
fragmentTransaction.add(android.R.id.content, fragment);
但是我收到了错误
FragmentTransaction类型中的方法add(int,Fragment)不适用于参数(int,ViewP)
答案 0 :(得分:0)
添加片段后必须添加此部分:
fragmentTransaction.commit();
http://developer.android.com/reference/android/support/v4/app/FragmentTransaction.html#commit()
(在下午12:33添加以下内容)
Fragment fragment = new ViewP();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(android.R.id.content, fragment);
fragmentTransaction.commit();