is it possible to save the .xml file from the screen to main.xml?
my requirement is to.. first i create a xml files with some files
the user selects the required fields and select the save button.
from next onwards the application directly show the user specified fields only
. directly by saving the selected field in the xml and remaining fields should be invisible the main.xml code is directly change to newly userspecified view....
Have you considered using SharedPreferences? From what I've read from your description I think it should cover your needs.
Related
I'm trying to make a app with some nice features. One of them is :
I want to modify the text that you see in my app on user request. By this I mean if you see the MENU name in my app and want to display it as MAIN MENU or MY MENU etc you press a button, open an edit interface, write the name,click ok and that's it, text changed.
Here is little part of my aplication, it's shows up Slide to change the brightness, but user want to change it to “Brighness changer” . Any ideeas how to do that ?
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Slide to change the brightness"
android:id="#+id/textView"
I know that all my names are saved in a strings.xml file , problems is that i don't want to recompile my app everytime user will make a change..that's the main problem. I need a way to do it to avoid this .
Thanks in advance !
You store the string they want to use in a shared preference. When you display this layout, read the value from the shared preference and call setText on the TextView to set the text. Use the existing string as the default, of course.
I have built application that enable the user to design his/her Business card. I have used absolute layout for the purpose of card designing. Now the problem is that how to enable the user to edit his/her card after saving the card. Do i have to save the XML of absolute layout to edit the card? or Is their any other method.
Please help me out. Thanks in advance.
First of all, you should not use AbsoluteLayout.
From the documentation:
This class was deprecated in API level 3.
Not sure exactly what are your needs, but a better choice would be RelativeLayout or a FrameLayout.
If you want to save the result layout, you might need to store all relevant information about the views in the tree and rebuild it once it is needed.
So for example, if you have a TextView in the card that a user added, save the text, color, margins, etc for that TextView. When needed, create a new TextView and restore the data.
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?
There are 4 activity and some edit text in each activity and i want to save all these edit text into a file on pressing one button and again have to restore all these on pressing other button
Shared preference is a good idea. see this (How to use SharedPreferences in Android to store, fetch and edit values)
Alternatively you think of other File IO.
Android also provide XML parser that could be another option depend on your requirement i guess. For SAX see this(How to parse XML using the SAX parser)
I have an ImageView on my scene that I would like to set the source of dynamically based on user input.
Let's say I have 4 images in my drawable folder: aaa.png, bbb.png, ccc.png, and ddd.png.
When my application loads I set the image to: aaa.png
myImageView.setImageResource(R.drawable.aaa);
now I have an EditText where a user can type in bbb and I want to change the image source to be the bbb.png, or user enters ccc, change source to ccc.png etc.
how can I dynamically set the parameter in setImageResource()? I tried playing around with the Drawable object to no avail...
If you want to allow open text input, you'll either have to use raw assets to fetch them by string name (see the sidenote on that page), or else use magical Java reflection to retrieve a field of the R class by name. Alternatively, you could keep a HashMap of strings to R.drawable integer values and look it up, but then you'd have to maintain that hashmap.
If you only want it to display images that you have loaded in your drawables you can use a Spinner where the id for the item is set to be the resource for the Drawable. That would be easier on your part and easier for the user.
If you want to use reflections have a look at the code below:
R.drawable ourRID = new R.drawable();
Field photoNameField = ourRID.getClass().getField("aaa");
myImageView.setImageResource(photoNameField.getInt(ourRID));
Hope it helps.