I created a simple app that has nothing except an EditText element. When I run the app, I type text into the element and then press Ctrl-F11 to change the emulator's orientation. I've added logging information to make sure that the activity gets destroyed and re-created when I change orientation. I haven't added any code to save the text in the EditText element and yet, after the change of orientation, the text that I typed stays in the EditText element. What mechanism in Android is saving and then restoring the element's text (is it savedInstanceState) and how can I see for myself the details of this saving operation?
onSaveInstanceState()/onRestoreInstanceState() along with unique widget IDs. Some links that utilize:
Saving Android Activity state using Save Instance State
http://groups.google.com/group/android-developers/browse_thread/thread/5d7fd8da11c8e971
Related
Everyone,
I would like to achieve the following in my Android App:
I would like to create a view in which there are several input fields.
An associated toolbar contains a save button.
If I have the focus in an EditText field and then press Save, I want the value of the edit field to be taken before saving.
So far I have created a workaround where a method resetFocus() is called before saving which does the following:
if (binding.volume.hasFocus()) binding.volume.clearFocus();
Is there a clean way to implement the request without such a help method?
Thx for you help
I am new to Android and I want to ask from you people. that I have a Android Activity named as Account Page, It shows the user his/her registration data. The Activity contains editable fields (EditText).
I want that initially, all The EditTexts are disabled and get enabled when I click on the Edit TextView (Button?). When the fields are enabled, the Edit TextView should read 'Apply'. When I click on 'Apply', then data should be modified, and the fields and Button restored to the initial state.
I am using this implementation using SharedPreferences in Android.
Kindly tell me how I can achieve this.
For disabling edittext: How to disable edittext in android
disable edittexts in onCreate() method or disable it using XML attribute.
In onClick method of Edit textview, enable all edittext and change text of textview to Apply.
In onClick method of Apply textview, first check if the text in textview is "Apply" and then update the date and set text back to Edit.
You can achieve this by mimicking the two 'states' of your form using two methods : init() and edit(). In the method init(), disable all fields that you want to disable and set the text of your Button/TextView to 'Edit'.
In the method edit(), enable all the above fields and set the text of your Button/TextView to 'Apply'.
All you need now is to correctly place calls to these methods. I suggest you place calls to init() when your Activity is created and after the user hits Apply.
Add a call to edit() whenever you set the text of your Button to 'Edit'.
I would love if you understood what I'm suggesting and coded it yourself.
I have an application that can edit the content of a XMl, pictures text audio, my problem is every time i exit the apps the content backs to its default value. Is there anyway to save the changes xml through runtime?
As of recently (probably as a new SDK feature), when I try to pull text from a Textview, I first get the method getFreezesText(), instead of getText().
I looked at the definition of this method and it says
**android:freezesText**
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol freezesText.
Related Methods
setFreezesText(boolean)
This tells nothing to me.
When we are supposed to use these methods (if ever at all)? Are they new or I've just noticed them?
If you want to force your TextView (or EditText etc. for that matter) to save its state you must add freezesText attribute:
<TextView
...
android:freezesText="true" />
From documentation on freezesText :
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider
The attribute and method have existed since API 1, so I'll say you just noticed it.
android:freezesText="true" will freeze your last completed text.
What is the last completed Text?
Suppose you are showing a textView which is changing after every 2 seconds everything is okay until you rotate the screen and if you rotate the screen the text inside textView will not be visible, here freezesText comes, it will freeze the last showed text (last completed Text).
I have a MainActivity wherein I am inserting a fragment over it.
In fragment there is EditText, Button ,TextView , ImageView.
When i enter some text in EditText it shows the same in TextView. And when i click on profile-image default Icon(Image View) it asks us to upload image from sd card and sets that as Profile Image.
Before clicking on submit button if i go to settings and change the language to say Japanese then after coming back to my app does not refresh the same using Japanese text. And even image uploaded but not saved also disappears.
I have values-ja for the Japanese script.
I read about onConfigChanges method in Activity. I tried that also but that method is also not getting called.
I think you should read those article, then you can solve your problem
How to refresh activity after changing language (Locale) inside application
Changing Locale within the app itself