Last active
November 16, 2018 11:58
-
-
Save mburumaxwell/5526215 to your computer and use it in GitHub Desktop.
Using menudrawer(SimonVT), viewpager and TitlePageIndicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" > | |
<com.viewpagerindicator.TitlePageIndicator | |
android:id="@+id/titlepageindicator" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:padding="10dip" /> | |
<com.tingle.abeltrac.ui.util.ViewPager | |
android:id="@+id/viewpager" | |
android:layout_width="fill_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tingle.abeltrac.ui.util; | |
import android.content.res.Resources; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import com.actionbarsherlock.app.SherlockFragmentActivity; | |
import com.tingle.abeltrac.R; | |
public class DevicePagerAdapter extends FragmentPagerAdapter { | |
private final Resources resources; | |
private Bundle args; | |
public DevicePagerAdapter(SherlockFragmentActivity activity, Bundle args) { | |
super(activity); | |
this.resources = activity.getResources(); | |
this.args = args; | |
} | |
@Override | |
public int getCount() { return 3; } | |
@Override | |
public Fragment getItem(int position) { | |
switch (position) { | |
case 0: | |
Frag1 fragment1 = new Frag1(); | |
fragment1.setArguments(args); | |
return fragment1; | |
case 1: | |
Frag2 fragment2 = new Frag2(); | |
fragment2.setArguments(args); | |
return fragment2; | |
case 2: | |
Frag3 fragment3 = new Frag3(); | |
fragment3.setArguments(args); | |
return fragment3; | |
default: | |
return null; | |
} | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
switch (position) { | |
case 0: | |
return resources.getString(R.string.frag1); | |
case 1: | |
return resources.getString(R.string.frag2); | |
case 2: | |
return resources.getString(R.string.frag3); | |
default: | |
return null; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tingle.abeltrac.ui; | |
import com.tingle.abeltrac.R; | |
import com.tingle.abeltrac.ui.util.DevicePagerAdapter; | |
import com.tingle.abeltrac.ui.util.ViewPager; | |
import com.viewpagerindicator.TitlePageIndicator; | |
public class ItemsActivity extends BaseSlidingActivity { | |
private DevicePagerAdapter adapter; | |
private ViewPager pager; | |
private TitlePageIndicator indicator; | |
private AbsDevicesAdapter abListAdapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
pager = (ViewPager) findViewById(R.id.viewpager); | |
indicator = (TitlePageIndicator) findViewById(R.id.titlepageindicator); | |
adapter = new DevicePagerAdapter(this, null); | |
pager.setAdapter(adapter); | |
indicator.setViewPager(pager, 1); | |
//difference: the page change listener should be set on the indicator and not the viewpager | |
indicator.setOnPageChangeListener(new MenuOnPageChangeListener(getMenuDrawer())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment