android的碎片问题
我正在使用android片段和查看寻呼机小部件。我想在定义的布局中添加更多的片段android的碎片问题,android,android-fragments,android-viewpager,Android,Android Fragments,Android Viewpager,我正在使用android片段和查看寻呼机小部件。我想在定义的布局中添加更多的片段 The issue is 当我试图通过代码输入一个片段时,总是会出错 下面是我的代码 public class Video extends FragmentActivity { MyPageAdapter pageAdapter; ViewPager pager; LinearLayout Video_content; @Override protected void on
The issue is
当我试图通过代码输入一个片段时,总是会出错
下面是我的代码
public class Video extends FragmentActivity {
MyPageAdapter pageAdapter;
ViewPager pager;
LinearLayout Video_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
Video_content = (LinearLayout)findViewById(R.id.Content);
FragmentTransaction t = getFragmentManager().beginTransaction();
//Add first fragment
MyFragment myFragment1 = new MyFragment();
我在这条线上出错了
t、 添加(Video_content.getId(),myFragment1,“myFirstFragment”)
下面是MyFragment类的代码:
import android.support.v4.app.Fragment;
public class MyFragment extends Fragment{
public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";
View v;
Handler updateHandler;
public static final MyFragment newInstance(String message)
{
MyFragment f = new MyFragment();
Bundle bdl = new Bundle(1);
bdl.putString(EXTRA_MESSAGE, message);
f.setArguments(bdl);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String message = getArguments().getString(EXTRA_MESSAGE);
v = inflater.inflate(R.layout.video_fragment, container, false);
TextView messageTextView = (TextView)v.findViewById(R.id.textView);
messageTextView.setText(message);
if(message.equals("Tv Shows"))
{
}
if(message.equals("Movies"))
{
}
if(message.equals("Music Videos"))
{
}
return v;
}
My Question is:
如何通过fragment添加通用布局并同时使用view pager?更改:
getFragmentManager()
到
初始化t
时,请使用supportFragmentManager
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
您确定使用了正确的
FragmentTransaction
和FragmentManager
类吗
我相信这一点
getFragmentManager().beginTransaction();
应该用这个来代替
getSupportFragmentManager().beginTransaction();
请上传问题中的错误日志。程序未编译。如上所述,它在这个statment t.add(Video_content.getId(),myFragment1,“myFirstFragment”)上给出了一个错误;酷,很高兴我能帮忙!
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
getFragmentManager().beginTransaction();
getSupportFragmentManager().beginTransaction();