我想從活動中創建FragmentPagerAdapter適配器。我如何做到這一點?從活動中調用FragmentPagerAdapter
當我從一個片段調用,但現在我想從一個活動中使用這種方式。
MyActivity.java
// here error
adapter = new FragmentPagerAdapter(getFragmentManager(),
images.getImageItem());
viewPage.setAdapter(adapter);
viewPage.setOnPageChangeListener(this);
FragmentPagerAdapter.java
public class FragmentPagerAdapter extends FragmentStatePagerAdapter {
private ArrayList<String> itemData;
public FragmentPagerAdapter(FragmentManager fm,
ArrayList<String> itemData) {
super(fm);
this.itemData = itemData;
}
@Override
public int getCount() {
return itemData.size();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
@Override
public Fragment getItem(int position) {
FragmentImageView f = FragmentImageView.newInstance();
f.setImageList(itemData.get(position));
return f;
}
}
什麼是錯誤? – Kartheek
@Kartheek構造函數FragmentPagerAdapter(FragmentManager,ArrayList)未定義 –