KingJA / SwitchButton

A smart switchable button,support multiple tabs. (多项选择器,切换按钮)
383 stars 76 forks source link

Any way to add tabs programmatically in code? #23

Open kevintanhongann opened 6 years ago

kevintanhongann commented 6 years ago

Any way to add tabs programmatically in code?

matiasgualino commented 5 years ago

I saw this method: setText(String... tagTexts).

mSwitchMultiButton.setText("点个Star", "狠心拒绝")

https://github.com/KingJA/SwitchButton/blob/1b2a8c876bae977f8007db52bcbf6104b0598b8a/libk-switchbutton/src/main/java/lib/kingja/switchbutton/SwitchMultiButton.java#L388

AnasLakhani commented 5 years ago

Yes Dont place array in arrays.xml place in java files in that way ::

private String[] tabTexts1 = {"General", "Password", "Address", "Avator"};

public void setSwitchMultiButton2 () {

    switchMultiButton2.setText(tabTexts1).setOnSwitchListener(new SwitchMultiButton.OnSwitchListener() {
        @Override
        public void onSwitch(int position, String tabText) {

            if (position == 0){

                viewPager1.setCurrentItem(0);

            } if (position == 1) {

                viewPager1.setCurrentItem(1);

            } if (position == 2) {

                viewPager1.setCurrentItem(2);

            } if (position == 3) {

                viewPager1.setCurrentItem(3);
            }

        }
    });

}

Set Like this Hope u like it