addisonElliott / SegmentedButton

Segmented Control/Button with animation for Android API 16+
Apache License 2.0
148 stars 39 forks source link

Deleting last segment error #45

Open bahaahany2019 opened 3 years ago

bahaahany2019 commented 3 years ago

Hi, I create segments at runtime all working fine my problem is in deleting the last segment for example if i have 3 segments i can delete the first & second without any problems but if i tried to delete the third the app crashes below is the delete code please advice.

btnDeleteSeg.setOnClickListener(new` View.OnClickListener()
    {
        @Override
        public void onClick (View v){
        bibleSegIndex = segmentedButtonGroup.getPosition();
        if (bibleSegIndex == 0) {
            segmentedButtonGroup.setPosition(0, false);
        } else {
            segmentedButtonGroup.setPosition(0, true);
        }
        segmentedButtonGroup.getButton(bibleSegIndex).setVisibility(View.GONE);
        segmentedButtonGroup.getButtons().remove(bibleSegIndex);
    }
    }