In my settings Fragment I have a password protected SwitchPreference
. I use it to unlock an "Edit mode" in the app. Not everyone should be allowed into this mode so I've put a password on it. However, this causes a problem.
Initially clicking the SwitchPreference
will switch it to the "ON" position, which will trigger my onSharedPreferenceChanged
method. However, if the person gets the password wrong, it will then switch it to the "OFF" position, which will then trigger my onSharedPreferenceChanged
method again!
So the problem is that I'm listening for when the SwitchPreference
gets changed, but I should be listening for when it gets clicked. A quick search on StackOverflow or Google will tell you that you shouldn't be trying to listen for a click, and should listen for the onSharedPreferenceChanged
. However, as I said, this doesn't suit my needs.
Does anyone know another method I can override here that will let me listen for when the SwitchPreference
is clicked?
My goal is to listen for a click, if its switch is "ON", then just turn if "OFF". But if it's "OFF", then popup a password dialog. If the password is correct, set the switch to "ON", otherwise leave it "OFF".
Thanks