android – ListView与Viewpager作为TabPageIndicator内的标题

android – ListView与Viewpager作为TabPageIndicator内的标题,第1张

概述所以我创建了一个片段活动,其中包含带有TabPageIndicator的Viewpager从片段滑动到另一个片段,并且在每个片段中我创建了一个ListView,其中包含一个ViewPager作为Header视图,问题是viewPager不刷卡即使我取消主ViewPager swipping 我用ActionBar标签尝试了同样的事情,但它也没有用   这是我的片段活动 public class S 所以我创建了一个片段活动,其中包含带有TabPageIndicator的VIEwpager从片段滑动到另一个片段,并且在每个片段中我创建了一个ListVIEw,其中包含一个VIEwPager作为header视图,问题是vIEwPager不刷卡即使我取消主VIEwPager swipPing

我用Actionbar标签尝试了同样的事情,但它也没有用

 

这是我的片段活动

public class SampleTabsstyled extends FragmentActivity {private static final String[] CONTENT = new String[] { "Recent","Artists","Albums","Songs","PlayLists","Genres" };@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.simple_tabs);    FragmentPagerAdapter adapter = new GoogleMusicAdapter(            getSupportFragmentManager());    final VIEwPager pager = (VIEwPager) findVIEwByID(R.ID.pager);    pager.setAdapter(adapter);    pager.setontouchListener(new OntouchListener() {        @OverrIDe        public boolean ontouch(VIEw v,MotionEvent event) {            // Todo auto-generated method stub            switch (event.getAction()) {            case MotionEvent.ACTION_MOVE:                pager.requestdisallowIntercepttouchEvent(true);                break;            case MotionEvent.ACTION_UP:            case MotionEvent.ACTION_CANCEL:                pager.requestdisallowIntercepttouchEvent(false);                break;            }            return true;        }    });    TabPageIndicator indicator = (TabPageIndicator) findVIEwByID(R.ID.indicator);    indicator.setVIEwPager(pager);}class GoogleMusicAdapter extends FragmentPagerAdapter {    public GoogleMusicAdapter(FragmentManager fm) {        super(fm);    }    @OverrIDe    public ListFragment getItem(int position) {        // return TestFragment.newInstance(CONTENT[position %        // CONTENT.length]);        return new SecondTestFragment();    }    @OverrIDe    public CharSequence getPageTitle(int position) {        return CONTENT[position % CONTENT.length].toupperCase();    }    @OverrIDe    public int getCount() {        return CONTENT.length;    }}

}

这是我的ListFragment

public class SecondTestFragment extends ListFragment {String[] countrIEs = new String[] { "India","Pakistan","Sri Lanka","China","Bangladesh","Nepal","Afghanistan","north Korea","South Korea","Japan" };VIEw mheaderVIEw;VIEwPager pager;@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {    /** Creating an array adapter to store the List of countrIEs **/    VIEw parent = inflater.inflate(R.layout.fragment_List,null);    // mheaderVIEw = inflater.inflate(R.layout.item_List,null);    mheaderVIEw = inflater.inflate(R.layout.featured_pager,null);    pager = (VIEwPager) mheaderVIEw.findVIEwByID(R.ID.featuredPaper);    pagerAdapter pa = new pagerAdapter(getActivity());    pager.setAdapter(pa);    pager.setontouchListener(new OntouchListener() {        @OverrIDe        public boolean ontouch(VIEw v,MotionEvent event) {            // Todo auto-generated method stub            Log.d("Motion Event",event.toString());            return false;        }    });    CirclePageIndicator indicator = (CirclePageIndicator) mheaderVIEw.findVIEwByID(R.ID.featured_indicator);    indicator.setVIEwPager(pager);    return parent;}@OverrIDepublic voID onActivityCreated(Bundle savedInstanceState) {    // Todo auto-generated method stub    super.onActivityCreated(savedInstanceState);    if (mheaderVIEw != null) {        this.getListVIEw().addheaderVIEw(mheaderVIEw);        Log.d("pager","not null");    } else {        Log.d("pager","null");    }    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),androID.R.layout.simple_List_item_1,countrIEs);    setlistadapter(adapter);    getListVIEw().setontouchListener(new VIEw.OntouchListener() {        @OverrIDe        public boolean ontouch(VIEw v,MotionEvent event) {            getListVIEw().getParent().requestdisallowIntercepttouchEvent(true);            return false;        }    });    ((PullToRefreshListVIEw) getListVIEw()).setonRefreshListener(new OnRefreshListener() {        @OverrIDe        public voID onRefresh() {            // Do work to refresh the List here.        }    });}

}

解决方法 在父视图寻呼机中覆盖canScroll方法.

@OverrIDeprotected boolean canScroll(VIEw v,boolean checkV,int dx,int x,int y) {   if(v != this && v instanceof VIEwPager) {       return true;   }   return super.canScroll(v,checkV,dx,x,y);}

检查这个答案

ViewPager inside ViewPager

总结

以上是内存溢出为你收集整理的android – ListView与Viewpager作为TabPageIndicator内的标题全部内容,希望文章能够帮你解决android – ListView与Viewpager作为TabPageIndicator内的标题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1122188.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存