java - Disable the tabswipe -


i having 3 tabs have created using android.support.v4.view.viewpager want stop swipe horizontally fingers should working when user taps on name of tab.

caloriebsearchheading.java

public class caloriebsearchheading extends fragmentactivity implements actionbar.tablistener {      private string[] tabs = { "recent","frequent","my foods" };     private string[] tabss = { "recent","frequent","my drinks" };     private viewpager viewpager;     private actionbar actionbar;     private tabscaloriebpageadapter madapter;     private string foodtype;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_caloriebsearchheading);         bundle bundle = getintent().getextras();         if(bundle != null){              foodtype = bundle.getstring("foodtype");          }         viewpager = (viewpager) findviewbyid(r.id.pagercalorieb);         actionbar = getactionbar();         madapter = new tabscaloriebpageadapter(getsupportfragmentmanager());          viewpager.setadapter(madapter);         actionbar.sethomebuttonenabled(false);         actionbar.setnavigationmode(actionbar.navigation_mode_tabs);                 actionbar.setstackedbackgrounddrawable(new colordrawable(color.parsecolor("#008080")));         if(foodtype.equals("drinks")){             (string tab_name : tabss) {                 actionbar.addtab(actionbar.newtab().settext(tab_name)                         .settablistener(this));             }         }         else{             (string tab_name : tabs) {                 actionbar.addtab(actionbar.newtab().settext(tab_name)                         .settablistener(this));             }         }         // adding tabs           /**          * on swiping viewpager make respective tab selected          * */         viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() {              @override             public void onpageselected(int position) {                 // on changing page                 // make respected tab selected                 actionbar.setselectednavigationitem(position);             }              @override             public void onpagescrolled(int arg0, float arg1, int arg2) {             }              @override             public void onpagescrollstatechanged(int arg0) {             }         });      }      @override     public void ontabselected(tab tab, fragmenttransaction ft) {          viewpager.setcurrentitem(tab.getposition());     }      @override     public void ontabunselected(tab tab, fragmenttransaction ft) {       }      @override     public void ontabreselected(tab tab, fragmenttransaction ft) {       }      @override     public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {         case android.r.id.home:             // app icon in action bar clicked; go home             intent intent = new intent(this, caloriemainactivity.class);             intent.addflags(intent.flag_activity_clear_top);             startactivity(intent);             return true;         default:             return super.onoptionsitemselected(item);          }     } 

caloriebsearchheading.xml

<android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/pagercalorieb"         android:layout_width="match_parent"         android:layout_height="match_parent" >      </android.support.v4.view.viewpager> 

tabone.java

 public class caloriebtabonerecentfood extends fragment{  //here have done work     } 

and same tab 2 , tab three. code should add stop swiping fingers.

try set limit in fragment activity.

 viewpager.setoffscreenpagelimit(number); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -