android - PagerSlidingTabStrip indicator light does not change with the page? -
it working search activity page not profile activity: indicator light under selected tab, have add something
here code:
public class profileactivity extends appcompatactivity implements view.onclicklistener { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_profile); getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().setdisplayshowhomeenabled(true); setrequestedorientation(activityinfo.screen_orientation_portrait); string[] tabtitles = {"completed", "joined"}; adapter = new tabadapter(getsupportfragmentmanager(), profilecompletedfrag, profilejoinedfrag, tabtitles); // // initialize viewpager , set adapter pager = (viewpager) findviewbyid(r.id.profilepager); pager.setadapter(adapter); // bind tabs viewpager tabs = (pagerslidingtabstrip) findviewbyid(r.id.profiletabs); tabs.setviewpager(pager); /** * on swiping viewpager make respective tab selected * */ tabs.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpageselected(int position) { // on changing page if (position == 0) { currentpage = 0; pager.setcurrentitem(0); } if (position == 1) { currentpage = 1; pager.setcurrentitem(1); } } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } }); ///////////// tabs.setontabreselectedlistener(new pagerslidingtabstrip.ontabreselectedlistener() { @override public void ontabreselected(int position) { toast.maketext(profileactivity.this, "tab reselected: " + position, toast.length_short).show(); if (position == 0) { currentpage = 0; pager.setcurrentitem(0); } if (position == 1) { currentpage = 1; pager.setcurrentitem(1); } } });
he xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/profileparentlayout"> <linearlayout android:orientation="horizontal" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/profilenamelayout" android:layout_alignparenttop="true" android:layout_margintop="20dp" android:layout_marginbottom="10dp"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/profilename" android:layout_centerinparent="true" android:text="bob marley"/> </linearlayout> <relativelayout android:layout_width="75dp" android:layout_height="75dp" android:layout_marginbottom="10dp" android:layout_centerhorizontal="true" android:id="@+id/profileimagelayout" android:layout_below="@+id/profilenamelayout"> <imageview android:layout_width="75dp" android:layout_height="75dp" android:id="@+id/profileimage" android:src="@drawable/camera_w" android:layout_centerinparent="true"/> <imageview android:id="@+id/editprofileimage" android:layout_height="30dp" android:layout_width="30dp" android:src="@drawable/ic_launcher" android:layout_alignparentright="true"/> </relativelayout> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_marginbottom="10dp" android:id="@+id/profiledetailslayout" android:layout_below="@id/profileimagelayout"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/profilefollowers" android:text="13 followers" android:textsize="20dp"/> <view android:id="@+id/separator" android:layout_marginleft="5dip" android:background="#ffffff" android:layout_width = "1dip" android:layout_height="fill_parent"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/profilefollowing" android:text="45 following" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:textsize="20dp" /> <view android:id="@+id/separator2" android:layout_marginright="5dip" android:background="#ffffff" android:layout_width = "1dip" android:layout_height="fill_parent"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/profilepoints" android:text="124 points" android:textsize="20dp"/> </linearlayout> <linearlayout android:layout_width="fill_parent" android:layout_height="?attr/actionbarsize" android:orientation="horizontal" android:id="@+id/tabslayout" android:layout_below="@+id/profiledetailslayout"> <!-- tabs --> <com.astuetz.pagerslidingtabstrip android:id="@+id/profiletabs" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:pstsshouldexpand="true" android:background="?attr/colorprimary"/> <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/profilepager" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v4.view.viewpager> </linearlayout> <gridview android:layout_below="@+id/tabslayout" android:id="@+id/profilegridview" android:layout_margintop="10dp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numcolumns="auto_fit" android:columnwidth="90dp" android:horizontalspacing="10dp" android:verticalspacing="10dp" android:gravity="center" android:stretchmode="columnwidth" > </gridview> </relativelayout>
public class tabadapter extends fragmentstatepageradapter { string[] tabtitles = {"completed", "joined"}; public tabadapter(fragmentmanager fragmentmanager) { // todo auto-generated constructor stub super(fragmentmanager); } @override public charsequence getpagetitle(int position) { // todo auto-generated method stub return tabtitles[position]; } @override public fragment getitem(int arg0) { switch (arg0) { case 0: return profiledatafagment.newinstance(0); case 1: return profiledatafagment.newinstance(1); default: break; } return null; } @override public int getcount() { // todo auto-generated method stub return 2; // number of views } }
// create profiledatafagment , set data according position
Comments
Post a Comment