2012-06-11 13 views
3

내가 내 FragmentPagerAdapter의 작업을 진행하려고하지만, 예를 실생활에 쉽게에 조금 있습니다 FragmentPagerAdapter instantiateItem이 단편과 함께 사용하고 있습니까?

@Override 
public Object instantiateItem(final ViewGroup container, final int position) 
{ 
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    int resId = 0; 
    switch (position) 
     { 
     case 0: 
      resId = R.layout.favorites_fragment; 
      break; 
     case 1: 
      resId = R.layout.nearby_list_fragment; 
      break; 
     default: 
      throw new IllegalArgumentException("Index cant be mapped to fragement:" + position); 
     } 

    final View view = inflater.inflate(resId, null); 

    viewPager.addView(view, 0); 

    return view; 
} 

내가 파편 메신저를 사용하려는거야으로

이미 내가 팽창 찾을 수있는 모든 예를 들어 나의이 방법을 혼동 거기 조각을 만드는 대신보기. 이 작업을 수행하는 방법?

PS : 임 ... 4.1 lib에는

감사를 ActionBarSherlock의를 사용하여, 옌스

정확히 당신이 뭘 하려는지

답변

3

? 수업의 정의를 보여주십시오. FragmentPagerAdapter을 확장하고 조각을 반환하려면 public abstract Fragment getItem(int position)을 구현해야합니다. 이 아니고 instantiateItem()을 덮어 쓰면 FragmentPagerAdapter에 이미 올바른 작업을 수행합니다.

+0

Arg,이 방법을 놓쳤습니다! 그것은 지금 작동합니다! 감사 니콜라이 – Kitesurfer

관련 문제