Android view pager with page indicator

后端 未结 7 1515
终归单人心
终归单人心 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条回答
  •  -上瘾入骨i
    2020-12-07 19:42

    Just an improvement to the nice answer given by @vuhung3990. I implemented the solution and works great but if I touch one radio button it will be selected and nothing happens.

    I suggest to also change page when a radio button is tapped. To do this, simply add a listener to the radioGroup:

    mPager = (ViewPager) findViewById(R.id.pager);
    final RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);    
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    switch (checkedId) {
                        case R.id.radioButton :
                            mPager.setCurrentItem(0, true);
                            break;
                        case R.id.radioButton2 :
                            mPager.setCurrentItem(1, true);
                            break;
                        case R.id.radioButton3 :
                            mPager.setCurrentItem(2, true);
                            break;
                    }
                }
            });
    

提交回复
热议问题