这是VIEwPager的页面适配器,用于在片段之间滑动:
import java.util.List;import com.app.name.fragments.TipsFragment;import androID.support.v4.app.Fragment;import androID.support.v4.app.FragmentManager;import androID.support.v4.app.FragmentPagerAdapter;import androID.support.v4.app.FragmentTransaction;import androID.vIEw.VIEwGroup;public class PageAdapter extends FragmentPagerAdapter { /** * */ List<Fragment> fragments; public PageAdapter(FragmentManager fm,List<Fragment> frags) { super(fm); fragments = frags; } @OverrIDe public Fragment getItem(int arg0) { // Todo auto-generated method stub return TipsFragment.newInstance(0,0); } @OverrIDe public int getCount() { // Todo auto-generated method stub return 4; } @OverrIDe public voID destroyItem(VIEwGroup container,int position,Object object) { FragmentManager manager = ((Fragment) object).getFragmentManager(); FragmentTransaction trans = manager.beginTransaction(); trans.remove((Fragment) object); trans.commit(); super.destroyItem(container,position,object); }}
这是我的提示片段:
public class TipsFragment extends Fragment{ public static TipsFragment newInstance(int image,int content) { TipsFragment fragment = new TipsFragment(); return fragment; } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw vIEw = inflater.inflate(R.layout.tip_layout,null); return vIEw; }}
如何修改我的代码以使用VIEws而不是Fragment?
解决方法 您需要覆盖这两个方法而不是getItem():@OverrIDepublic Object instantiateItem(VIEwGroup collection,int position) { VIEw v = layoutInflater.inflate(...); ... collection.addVIEw(v,0); return v;}@OverrIDepublic voID destroyItem(VIEwGroup collection,Object vIEw) { collection.removeVIEw((VIEw) vIEw);}总结
以上是内存溢出为你收集整理的android – 我可以使用带有视图的视图寻呼机(不带片段)全部内容,希望文章能够帮你解决android – 我可以使用带有视图的视图寻呼机(不带片段)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)