MultiSelectListPreference not storing values?

后端 未结 1 454
花落未央
花落未央 2020-12-20 00:49

I\'m rather new to Android App developing so maybe I\'m just making a simple newbie mistake, but here\'s my problem: I have 2 simple Activities, MainActivity and SettingsAct

1条回答
  •  清歌不尽
    2020-12-20 01:25

    I spent some time yesterday on this and am now convinced that it is not intended like that, but actually broken - someone confused reference by pointer and by value. ;-)

    Seems to be fixed in the more current versions of Android (since 4.1) though: https://code.google.com/p/android/issues/detail?id=22807

    The way I solved it now for the previous versions of Android is to override the setValues method in my implementation of MultiSelectListPreference and just copy the values into a new object:

    @Override
    public void setValues( Set values ) {
    
        //Workaround for https://code.google.com/p/android/issues/detail?id=22807
        final Set newValues = new HashSet();
        newValues.addAll( values );
        super.setValues( newValues );
    }
    

    0 讨论(0)
提交回复
热议问题