我在VideoActivity.java.Below收到编译时错误The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, VideoListFragment, String)
我发布了与此相关的代码。
VideoActivity.java:
package com.sit.loco.activity;
import android.support.v4.app.Fragment;
import com.loco.android.R;
import com.sit.loco.frgment.VideoListFragment;
import android.support.v4.app.FragmentActivity;
public class VideoActivity extends FragmentActivity implements ActionBar.OnNavigationListener, VideoListFragment.OnVideoSelectedListener{
// create object of ActionBar and VideoListFragment
ActionBar actionBar;
VideoListFragment videoListFrag;
int selectedItem;
private String TAG;
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
// TODO Auto-generated method stub
selectedItem = itemPosition;
// create object of VideoListFragment and send data position to that fragment
videoListFrag = new VideoListFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", itemPosition);
videoListFrag.setArguments(bundle);
// call video list fragment with new data
getFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, videoListFrag, "VIDEO_LIST_FRAGMENT")--->Error at Compile time
.commit();
return true;
}
}
VideoListFragment.java:
package com.sit.loco.frgment;
import android.support.v4.app.Fragment;
public class VideoListFragment extends Fragment {
OnVideoSelectedListener mCallback;
boolean loadingMore = false;
}
MyFragmentPagerAdapter.java:
package com.sit.loco.provider;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 6;
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
/** This method will be invoked when a page is requested to create */
@Override
public Fragment getItem(int arg0) {
Bundle data = new Bundle();
switch (arg0) {
case 4:
VideoListFragment videoList = new VideoListFragment();
data.putInt("position", arg0);
videoList.setArguments(data);
return videoList;
}
}
}
我不知道如何解决这个问题。任何人都可以帮助我。谢谢。
答案 0 :(得分:0)
您无法将FragmentManager与使用支持包(android.support.v4.app.Fragment
)的Fragment一起使用
将getFragmentManager()
替换为getSupportFragmentManager()