2014-11-23 2 views
1

Привет, я пытаюсь разработать приложение с помощью Navigation Drawer и Swipe Tabs, и я сделал это на картинке, но здесь все вкладки расположены в одном фрагменте, я могу разделить и сделать фрагмент для каждого другие вкладки (пункт 1, пункт 2 ...) внутри вы можете помочь мне сделать фрагмент с ECH другой (пункт 1, пункт 2 ...) и как и где добавить благодаря enter image description hereКак сделать фрагменты для каждой вкладки Swipe в навигационном ящике

private SlidingTabLayout mSlidingTabLayout; 
private ViewPager mViewPager; 

public ScreenOne() { 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) { 

View rootView = inflater.inflate(R.layout.screen_one, container, false); 

return rootView; 
} 

    @Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
// Get the ViewPager and set it's PagerAdapter so that it can display items 
mViewPager = (ViewPager) view.findViewById(R.id.viewpager); 
mViewPager.setAdapter(new SamplePagerAdapter()); 

// Give the SlidingTabLayout the ViewPager, this must be 
// done AFTER the ViewPager has had it's PagerAdapter set. 
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs); 
mSlidingTabLayout.setViewPager(mViewPager); 
} 

// Adapter 
class SamplePagerAdapter extends PagerAdapter { 

/** 
* Return the number of pages to display 
*/ 
@Override 
public int getCount() { 
    return 10; 
} 

/** 
* Return true if the value returned from is the same object as the View 
* added to the ViewPager. 
*/ 
@Override 
public boolean isViewFromObject(View view, Object o) { 
    return o == view; 
} 

/** 
* Return the title of the item at position. This is important as what 
* this method returns is what is displayed in the SlidingTabLayout. 
*/ 
@Override 
public CharSequence getPageTitle(int position) { 
    return "Item " + (position + 1); 
} 

/** 
* Instantiate the View which should be displayed at position. Here we 
* inflate a layout from the apps resources and then change the text 
* view to signify the position. 
*/ 
@Override 
public Object instantiateItem(ViewGroup container, int position) { 
    // Inflate a new layout from our resources 
    View view = getActivity().getLayoutInflater().inflate(R.layout.pager_item, 
      container, false); 
    // Add the newly created View to the ViewPager 
    container.addView(view); 

    // Retrieve a TextView from the inflated View, and update it's text 
    TextView title = (TextView) view.findViewById(R.id.item_title); 
    title.setText(String.valueOf(position + 1)); 

    // Return the View 
    return view; 
} 

/** 
* Destroy the item from the ViewPager. In our case this is simply 
* removing the View. 
*/ 
@Override 
public void destroyItem(ViewGroup container, int position, Object object) { 
    container.removeView((View) object); 
} 
} 
} 

ответ

1

Что вам нужно a Fragment Pager Adapater вместо обычного PagerAdapter. Проверьте документацию, он имеет очень полный рабочий пример.

+0

будет работать с моим экраном один фрагмент, потому что ему нужен FragmentAktivity – Sultan

+0

Да, он будет работать. Пока вы используете диспетчер дочерних фрагментов, все должно быть в порядке. В основном, замените эту строку 'mAdapter = new MyAdapter (getSupportFragmentManager());' by_mAdapter = new MyAdapter (getChildFragmentManager()); ' –

+0

это означает, что я должен изменить Screen one на FragmentAktivity, а затем добавить адаптер? – Sultan

Смежные вопросы