i want to get and set the value of controls define in XML Layout file at run time and save that value in another XML file .
i want to modify the state of the screen objects, including those declared
in XML, at run time.
Thanks and Regards
RizN81
-
1question was not clearly. can more elaborate what exactly you want to try?Pratik– Pratik2011-12-22 07:14:52 +00:00Commented Dec 22, 2011 at 7:14
-
2At run time, you can't change any values in any resource files. What problem are you trying to solve that makes you want to try this?Ted Hopp– Ted Hopp2011-12-22 07:15:42 +00:00Commented Dec 22, 2011 at 7:15
-
Please be more specific describing your questionEgor– Egor2011-12-22 07:16:56 +00:00Commented Dec 22, 2011 at 7:16
-
@TedHopp agree!! XML layout file can't updated by using code, but you can set individual attributes of any views by code.Paresh Mayani– Paresh Mayani2011-12-22 07:23:01 +00:00Commented Dec 22, 2011 at 7:23
-
i want to get values from the XML files (layout) and then save that value in another XML file(e.g AppSettings) and then use that value store in the XML file(e.g AppSettings) in any Class of my APPRizN81– RizN812011-12-22 07:26:29 +00:00Commented Dec 22, 2011 at 7:26
Add a comment
|
1 Answer
The easiest thing to do is to define the values you want to capture separately from the layout files. Then you can retrieve the values directly. For instance:
some layout file
<Button
android:paddingLeft="@dimen/left_padding"
android:checked="@bool/default_checked"
. . .
/>
some file in res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="left_padding">3dp</dimen>
<bool name="default_checked">true</bool>
. . .
</resources>
In view code
Resources res = getResources();
int leftPadding = res.getDimension(R.dimen.left_padding);
boolean defaultChecked = res.getBoolean(R.bool.default_checked);
You can then save leftPadding and defaultChecked in an XML file (but not a resource file!), in shared preferences, etc. But I think it would be easiest to just retrieve the resource value directly each time you need it.
7 Comments
RizN81
ok but what if i define the value in xml layout(for eg:android:checked="true") and want to store that value in another file?
RizN81
i want to save the
3dp value in to resources take from EditText at runtime from xml.Ted Hopp
@RizN81 - Why do you need to save the
3dp value again? It's already there as a resource value.RizN81
you not understand what i am saying .you define the value in resources file but i want to get that value from the user and then save the value in resources file.
|