我用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内的标题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)