Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EventsActivity extends SherlockFragmentActivity {
- ViewPager mViewPager;
- TabsAdapter mTabsAdapter;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- requestWindowFeature(com.actionbarsherlock.view.Window.FEATURE_NO_TITLE);
- super.onCreate(savedInstanceState);
- mViewPager = new ViewPager(this);
- mViewPager.setId(R.id.pager);
- setContentView(mViewPager);
- setTitle("Events");
- ActionBar bar = getSupportActionBar();
- bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- mTabsAdapter = new TabsAdapter(this, mViewPager);
- mTabsAdapter.addTab(bar.newTab().setText("Featured"),
- EventsFeatured.class, null);
- mTabsAdapter.addTab(bar.newTab().setText("All"), EventsAll.class, null);
- mTabsAdapter.addTab(bar.newTab().setText("Nearby"), EventsNearBy.class,
- null);
- }
- public static class TabsAdapter extends FragmentPagerAdapter implements
- ActionBar.TabListener, ViewPager.OnPageChangeListener {
- private final Context mContext;
- private final ActionBar mActionBar;
- private final ViewPager mViewPager;
- private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
- static final class TabInfo {
- private final Class<?> clss;
- private final Bundle args;
- TabInfo(Class<?> _class, Bundle _args) {
- clss = _class;
- args = _args;
- }
- }
- public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) {
- super(activity.getSupportFragmentManager());
- mContext = activity;
- mActionBar = activity.getSupportActionBar();
- mViewPager = pager;
- mViewPager.setAdapter(this);
- mViewPager.setOnPageChangeListener(this);
- }
- public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
- TabInfo info = new TabInfo(clss, args);
- tab.setTag(info);
- tab.setTabListener(this);
- mTabs.add(info);
- mActionBar.addTab(tab);
- notifyDataSetChanged();
- }
- @Override
- public int getCount() {
- return mTabs.size();
- }
- @Override
- public Fragment getItem(int position) {
- TabInfo info = mTabs.get(position);
- return Fragment.instantiate(mContext, info.clss.getName(),
- info.args);
- }
- public void onPageScrolled(int position, float positionOffset,
- int positionOffsetPixels) {
- }
- public void onPageSelected(int position) {
- mActionBar.setSelectedNavigationItem(position);
- }
- public void onPageScrollStateChanged(int state) {
- }
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
- Object tag = tab.getTag();
- for (int i = 0; i < mTabs.size(); i++) {
- if (mTabs.get(i) == tag) {
- mViewPager.setCurrentItem(i);
- }
- }
- }
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
- }
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
- }
- }
- EVENTS FEATURED CLASS:
- public class EventsFeatured extends SherlockFragment {
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater
- .inflate(R.layout.events_featured, container, false);
- Button b = (Button) view.findViewById(R.id.buttonA);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Toast.makeText(getSherlockActivity(), "Button Clicked", 0)
- .show();
- }
- });
- return view;
- }
- }
- EVENTS ALL CLASS:
- public class EventsAll extends SherlockFragment {
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.events_all, container, false);
- Button b = (Button) view.findViewById(R.id.buttonA);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Toast.makeText(getSherlockActivity(), "Button Clicked", 0)
- .show();
- }
- });
- return view;
- }
- }
- EVENTS NEARBY CLASS:
- public class EventsNearBy extends SherlockFragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.events_nearby, container, false);
- return view;
- }
- }
- events.xml:
- <?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="wrap_content"
- android:orientation="vertical" >
- <android.support.v4.view.ViewPager
- android:id="@+id/pager"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- </android.support.v4.view.ViewPager>
- </LinearLayout>
- events_featured.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <ScrollView
- android:id="@+id/scrollView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true" >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="Featured"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- <ProgressBar
- android:id="@+id/progressBar1"
- style="?android:attr/progressBarStyleLarge"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView1"
- android:layout_below="@+id/textView1"
- android:layout_marginLeft="26dp"
- android:layout_marginTop="42dp" />
- <Button
- android:id="@+id/buttonA"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_above="@+id/textView1"
- android:layout_alignLeft="@+id/textView1"
- android:layout_marginBottom="59dp"
- android:text="Button" />
- </LinearLayout>
- </ScrollView>
- </RelativeLayout>
- events_all.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="Featured All"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- <Button
- android:id="@+id/buttonA"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_above="@+id/textView1"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="21dp"
- android:text="Two" />
- </RelativeLayout>
- events_nearby.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="Near By"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement