How to use different resources in android app based on user settings? - android

I am working on an application that asks the user for specific settings at the start. For example, my first activity asks the user:
Use option?
-option A
-option B
Now, after the user selects what option he/she will use I would like to be able to change the resources my app uses. I am specifically talking about the values/strings.xml where I have different strings for different options of the application.
For now, I am using option A as the default one and I put all the strings in the default strings.xml file and for now option B shares the same strings, however I am expecting option B to need a few specific strings that I will need to define in another file, but cannot figure out a way to decide what is the best approach to do this?
Thanks in advance
EDIT:
To answer jkhouw1's question, option B will only change existing strings. If I was to use string arrays as resources, how would I be able to specify this in my layout.xml file and then be configured by what the user chose on the first activity? - to translate this in an example:
If I have a TextView I want to define its text in the layout.xml like <TextView android:text="#string/(key)" />
If I was to use string arrays for the not common strings, how could I define the android:text attribute for my View in the layout.xml file depending on what option the user selects?
Thanks

Unfortunately, there doesn't seem to be a way to do what I am trying above currently.

Related

how to getstandard value from Spinner with multilanguage app on Android

I've an App where user can post photo and give some attributes to it.
Users can determine which category the photo belongs within a set of default categories, i try to show the categories options in a Spinner and the values come from a xml array compiled into the app.
This way i can show the categories in whichever language user is running the app.
The problem i have is to convert the value got from spinner back into a standard set for store in my database. Because depending of what language user set, i get the value as a different word and is a nightmare to create a converter which could handle it and translate from N different languages into my standard enum.
I would like to do something like radiobutton, like each option has a label (in whatever langague user wants) and a value (which i can define in a stardard way) so when i get selectedItemValue() i always get same value independent of language.
Is there any way to do that?
I advise you to use res/raw/ with different qualifiers depending on your locals instead of using string array.
It helps you to store json files in them. So you can have a list of custom objects which have both title and id.
And you store id in the database, and id is the same in all locals.

How to modify a text view in app on user request

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.

Android Strings xml stores every value?

Do we have to place every text that we have to type in buttons or inputs or on plain surface of an activity.what happens if we don't provide values of text strings to strings xml??
what happens if we don't provide values of text strings to strings
xml??
you will get a lot of warnings from lint and no strings localization
Using strings.xml is mainly for localization, it's easy to translate a XML file and use it, not using strings.xml is a headache later on when you want to translate your app.
You may not use it, but maybe later you'll regret it.
Besides localization, it's very handy to have all strings located in the same place, when for instance, you have to change some label or correct some messages displayed to users.
Looking for strings in the code afterward could be a real pain when thousand of lines of code are produced.

Dynamically generate android XML

I´ve been working on a project, where the user should be able to choose an option from a spinner and depending on the selection, a specific form should be generated.
Now, I just have one standard android-xml for all the selections, and an onItemSelectedListener for the spinner.
I´m not sure how to get this going. Should I generate all the layout in plain java, or should I make a xml-layout to include in some way?
If I understand it well you want to create a short of configurable form.
To do so you can create a XML layout with all the available options of the form. Then by code, depending on the user selection add or quit elements with the View setVisibility() method and show the layout.
In case you have many forms or they are too big or complex, you can have as many XML layouts as different forms you have and then show one or another based on the user selection.

Android - EditText to StringArray stored in xml

Ive been attempting to work out how to take the text from an edittext box and move it into a string array located in strings.xml.
Basically its a user form which the user fills in, onClick it adds the information to the database and is then viewable in a listview. The listview and everything works fine but i cant work out to put in information using edittext boxes.
Any hints or techniques would be very much appreciated.
Thanks
You want to take user input for an edit text, and put it in strings.xml? You can't do that. String resources are for static strings, not things that will change at runtime. You should look at other data storage options, like shared preferences. See data storage.
I could be wrong (someone please correct me if I am), but I don't believe strings.xml is editable at runtime. Rather, it's a set of predefined resources that your app has access to, and it cannot be modified by the program--only read.
If you're looking to make this information available to your app for subsequent uses, you should look at using SharedPreferences: http://developer.android.com/guide/topics/data/data-storage.html#pref
No way. You can't do such a thing. Surely not with strings.xml and androidmanifest.xml too.
The other option you have is: if you already have some values in strings.xml, you can fetch them in an list and append your own values that you want from user. After that, put it in an adapter and display it in a list view like you usually do.

Categories

Resources