마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Fragment로 탭레이아웃 구성 질문입니다.

0 추천

 Fragment로 탭레이아웃 구성 질문입니다.

안드로이드 스튜디오에서 자동생성하면 소스가 생성되는데

탭은 3개인데  레이아웃 xml파일은 2개입니다.

잘 고치면 조금만 수정해서 탭한개당 1개 레이아웃 xml파일 사용하게 할수있을것 같은데 못하겠습니다

 

 

        public PlaceholderFragment() {
        }

       public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main2, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
            textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
            return rootView;
        }
    }


    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
//            return PlaceholderFragment.newInstance(position + 1);
            switch(position) {
                case 0:
                    return PlaceholderFragment.newInstance(position + 1);
                case 1:
                    return PlaceholderFragment2.newInstance(position + 1);
                case 2:
                    //return new Tab3(mContext);
            }
            return null;
        }
너부리이놈 (370 포인트) 님이 2016년 4월 21일 질문

1개의 답변

0 추천
PlaceholderFragment를 이름 다르게 3개 만들고, 각 파일 안에서 호출하는 레이아웃 파일 fragment_main2도 3개 만들어서 다르게 호출하게 하면 됩니다.
쎄미 (162,410 포인트) 님이 2016년 4월 22일 답변
...