Lock page fragment in ViewPager android -
how can lock paging in fragment activity of viewpager fragment swipe.i'm performing operations using progressbar in 1 fragment.while progressing progressbar fragment gets changes because of swipe action.so while progessing progressbar want stop swiping.how this?is there solution??
activity.xml file-
<android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainfragmentactivity" > <android.support.v4.view.pagertitlestrip android:id="@+id/pager_title_strip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="@drawable/title" android:paddingbottom="4dp" android:paddingtop="4dp" android:textcolor="#fff" /> </android.support.v4.view.viewpager>
fragment activity-
public class mainfragmentactivity extends fragmentactivity { private sectionspageradapter msectionspageradapter; private viewpager mviewpager; private context mcontext; private pagertitlestrip pt; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.activity); msectionspageradapter = new sectionspageradapter(getsupportfragmentmanager(),mcontext); mcontext=this; mviewpager = (viewpager) findviewbyid(r.id.pager); mviewpager.setadapter(msectionspageradapter); pt=(pagertitlestrip) findviewbyid(r.id.pager_title_strip); }
sectionspageradapter-
public class sectionspageradapter extends fragmentpageradapter { context mcontext; fragment fragment; public sectionspageradapter(fragmentmanager fm, context context) { super(fm); mcontext=context; } @override public fragment getitem(int position) { // getitem called instantiate fragment given page. // return dummysectionfragment (defined static inner class // below) page number lone argument. if(position==0){ fragment = new selectitem(); bundle args = new bundle(); args.putint(arg_section_number, position + 1); fragment.setarguments(args); } if(position==1){ fragment = new culation(); bundle args = new bundle(); args.putint(arg_section_number, position + 1); fragment.setarguments(args); } if(position==2){ fragment = new graphdisplay(); bundle args = new bundle(); args.putint(arg_section_number, position + 1); fragment.setarguments(args); } return fragment; } @override public int getcount() { return 3; } @override public charsequence getpagetitle(int position) { switch (position) { case 0 : return "select item"; case 1: return "calculation"; case 2: return "graph"; } return null; } }
try setting clickable false:
mviewpager.setclickable(false);
if works can create function in activity disable swipe event on view pager , call function in fragment in event of progress bar show , function enable it.
subclass viewpager , override ontouch event example:
edit
public class nonswipeableviewpager extends viewpager { private boolean lock; public void lock(){ lock=true; } public void unlock(){ lock=false; } public nonswipeableviewpager(context context) { super(context); } public nonswipeableviewpager(context context, attributeset attrs) { super(context, attrs); } @override public boolean ontouchevent(motionevent event) { if(lock) return false;else{ return super.ontouchevent(event); } } }
reference: how disable paging swiping finger in viewpager still able swipe programmatically?
Comments
Post a Comment