|
| 1 | +/* |
| 2 | + * Copyright (C) 2013 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.saulmm.material.slidingtabs.fragments; |
| 18 | + |
| 19 | + |
| 20 | +import android.app.Fragment; |
| 21 | +import android.os.Bundle; |
| 22 | +import android.support.v4.view.PagerAdapter; |
| 23 | +import android.support.v4.view.ViewPager; |
| 24 | +import android.util.Log; |
| 25 | +import android.view.LayoutInflater; |
| 26 | +import android.view.View; |
| 27 | +import android.view.ViewGroup; |
| 28 | + |
| 29 | +import com.saulmm.material.R; |
| 30 | +import com.saulmm.material.slidingtabs.views.SlidingTabLayout; |
| 31 | + |
| 32 | + |
| 33 | +public class SlidingTabsBasic extends Fragment { |
| 34 | + |
| 35 | + static final String LOG_TAG = "SlidingTabsBasicFragment"; |
| 36 | + |
| 37 | + @Override |
| 38 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 39 | + Bundle savedInstanceState) { |
| 40 | + return inflater.inflate(R.layout.fragment_sliding, container, false); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void onViewCreated(View view, Bundle savedInstanceState) { |
| 45 | + ViewPager mViewPager = (ViewPager) view.findViewById(R.id.viewpager); |
| 46 | + mViewPager.setAdapter(new SamplePagerAdapter()); |
| 47 | + |
| 48 | + SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs); |
| 49 | + mSlidingTabLayout.setViewPager(mViewPager); |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + class SamplePagerAdapter extends PagerAdapter { |
| 54 | + final String [] TITLES = {"CATEGORIES", "HOME", "TOP SELLING", "TOP GAMES", "TOP GROSSING"}; |
| 55 | + |
| 56 | + @Override |
| 57 | + public int getCount() { |
| 58 | + return 5; |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean isViewFromObject(View view, Object o) { |
| 64 | + return o == view; |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + @Override |
| 69 | + public CharSequence getPageTitle(int position) { |
| 70 | + return TITLES[position]; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public Object instantiateItem(ViewGroup container, int position) { |
| 75 | + |
| 76 | + View view = getActivity().getLayoutInflater().inflate(R.layout.item_sliding_pager, |
| 77 | + container, false); |
| 78 | + |
| 79 | + container.addView(view); |
| 80 | + |
| 81 | + return view; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public void destroyItem(ViewGroup container, int position, Object object) { |
| 86 | + container.removeView((View) object); |
| 87 | + Log.i(LOG_TAG, "destroyItem() [position: " + position + "]"); |
| 88 | + } |
| 89 | + |
| 90 | + } |
| 91 | +} |
0 commit comments