1

In my application I have a list of accounts in the settings screen. If you click on an account you go to a screen showing the account details. The account name is an EditTextPreference, if you click on it Android shows a dialog enabling you to change the name of the account.

The very first time this dialog is shown there is no value specified. The user enters the new name for the account and clicks OK and the account name is updated.

The problem is when I then view a different accounts details and click on its name to edit it, the dialog is showing the text from my previous rename. Why is this not showing no value or the current name of the account? Why is it reusing a value from a different account?

enter image description here

se22as
  • 2,282
  • 5
  • 32
  • 54

2 Answers2

0

The problem caused because you use one dialog for all accounts.

You should clear Edit text after press OK, also you should use SharedPreference to store the the details of each account.

Eng.Adi
  • 1
  • 2
  • How would I clear the "Edit Text" on pressing OK? This dialog is Androids and I dont have any control over it. I only get called into my "onSharedPreferenceChanged" which contains the SharedPreference and key and not the textbox from that dialog – se22as Nov 30 '18 at 13:04
0

The problem was caused because shared preference name is "global". So when you open the preference for one account you are getting the value that was last set.

The fix we have done is in our setting's screen's onCreate() we reset the account name preference to the name of the account the setting screen is for. Then when the edit name dialog is opened it has the correct account name.

se22as
  • 2,282
  • 5
  • 32
  • 54