Android view pager with page indicator

后端 未结 7 1532
终归单人心
终归单人心 2020-12-07 19:23

I need to get page indicator in the view pager file with images. Here is my code.

public class IndicatorActivity extends Activity {


 /** Called when the ac         


        
7条回答
  •  我在风中等你
    2020-12-07 19:53

    UPDATE: 22/03/2017

    main fragment layout:

           
    
                
    
                
    
                    
    
                    
    
                    
                
            
    

    set up view and event on your fragment like this:

            mViewPaper = (ViewPager) view.findViewById(R.id.viewpager);
            mViewPaper.setAdapter(adapder);
    
            mPageGroup = (RadioGroup) view.findViewById(R.id.page_group);
            mPageGroup.setOnCheckedChangeListener(this);
    
            mViewPaper.addOnPageChangeListener(this);
    
           *************************************************
           *************************************************
    
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
    
        @Override
        public void onPageSelected(int position) {
            // when current page change -> update radio button state
            int radioButtonId = mPageGroup.getChildAt(position).getId();
            mPageGroup.check(radioButtonId);
        }
    
        @Override
        public void onPageScrollStateChanged(int state) {
        }
    
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
            // when checked radio button -> update current page
            RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
            // get index of checked radio button
            int index = radioGroup.indexOfChild(checkedRadioButton);
    
            // update current page
            mViewPaper.setCurrentItem(index), true);
        }
    

    custom checkbox state: Custom checkbox image android

    Viewpager tutorial: http://architects.dzone.com/articles/android-tutorial-using

    enter image description here

提交回复
热议问题