segmentedview icon indicating copy to clipboard operation
segmentedview copied to clipboard

横竖屏旋转后,选中的分段会重置为第一个

Open ssyijiu opened this issue 7 years ago • 0 comments

没有在 View 中保存恢复状态,可以在 SegmentedView 添加下面代码解决:

    private static final String SEGMENTED_VIEW = "segmented_view";
    private static final String SEGMENTED_VIEW_INDEX = "segmented_view_index";


    @Override protected Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable(SEGMENTED_VIEW, super.onSaveInstanceState());
        bundle.putInt(SEGMENTED_VIEW_INDEX, mCurrentIndex);
        return bundle;
    }


    @Override protected void onRestoreInstanceState(Parcelable state) {
        if (state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            mCurrentIndex = bundle.getInt(SEGMENTED_VIEW_INDEX);
            super.onRestoreInstanceState(bundle.getParcelable(SEGMENTED_VIEW));
            return;
        }
        super.onRestoreInstanceState(state);
    }

ssyijiu avatar Jun 26 '17 01:06 ssyijiu