1

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

5
  • 1
    question was not clearly. can more elaborate what exactly you want to try? Commented Dec 22, 2011 at 7:14
  • 2
    At 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? Commented Dec 22, 2011 at 7:15
  • Please be more specific describing your question Commented 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. Commented 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 APP Commented Dec 22, 2011 at 7:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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?
i want to save the 3dp value in to resources take from EditText at runtime from xml.
@RizN81 - You can do the same thing with boolean values (and just about any attribute value). (I updated my example to show this.) See the docs for all the other resource types you can define.
@RizN81 - Why do you need to save the 3dp value again? It's already there as a resource value.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.