안녕하세요 구글링을 찾아보다가 찾지 못하고 - TopicsExpress



          

안녕하세요 구글링을 찾아보다가 찾지 못하고 생코에 여쭤보고 싶어서 글을 올립니다. 현재 안드로이드 하나의 액티비티에 ViewPager를 사용해서 프래그먼트를 교체하는 코드를 작성했는데요. 문제는 프래그먼트 교체는 잘 되는데 ViewPager의 숫자가 증감되지 않고 변화없이 계속 1입니다. 숫자가 증가하거나 감소하지 않는 이유를 찾지 못하고 있습니다. 혹시 ViewPager의 숫자가 변화가 없는 이유나 이런 현상을 야기하는 요인들이 무엇인지 알려주시면 감사하겠습니다. 참고했던 예제에서 차이점은 프래그먼트 레이아웃에 동적으로 ImageView를 추가하기 위해서 프래그먼트를 포함하고 있는 액티비티에서 프래그먼트를 생성할 때 context를 프래그먼트 생성자로 넘겨주게 했다는 점 외에는 없습니다. 예제로 참고했던 예제 출처는 emstudio.kr/2014/01/12/94/ 입니다. 제 코드는 액티비티 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext(); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.all_desire_star); mViewPager = (ViewPager) findViewById(R.id.alldesirestar_pager); mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mPagerAdapter); /*currentFragmentIndex = FRAGMENT_ONE; fragmentReplace(currentFragmentIndex);*/ } private class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // 해당하는 page의 Fragment를 생성합니다. return SpaceFragment.create(position, context); } @Override public int getCount() { return 5; // 총 5개의 page를 보여줍니다. } 프래그먼트 public class SpaceFragment extends Fragment{ Context context; RelativeLayout test; ArrayList arrStar; private int mPageNumber; final static int MAX_STAR = 12; public static SpaceFragment create(int pageNumber, Context context) { SpaceFragment fragment = new SpaceFragment(context); Bundle args = new Bundle(); args.putInt(page, pageNumber); fragment.setArguments(args); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View v = inflater.inflate(R.layout.fragment_space, container, false); test = (RelativeLayout)v.findViewById(R.id.fragment_spaceview); ((TextView) v.findViewById(R.id.num)).setText(mPageNumber + 1 + ); return v; } }
Posted on: Tue, 25 Nov 2014 22:30:26 +0000

Trending Topics



Recently Viewed Topics




© 2015