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.
Related
I'm building an Android app whose settings include a blacklist, so the user can input a list of words. I took a look at the TextPreference but it doesn't really fit the scope since it's a dialog with little space.
Is there any preference (built-in or library) I can use for inserting a list of words? A bigger text area with no dialog should be enough. I didn't think that such a simple preference is not available.
Storing a blacklist of words is probably a little out of scope for SharedPreferences, since they are designed to maintain simple key:value pairs.
You should create a new Fragment that allows users to manage the blacklist and then implement your own data persistence. If you use Sqlite and create a clustered index on the column word, you will have O(log(n)) search. Opposed to O(n) search that scanning the csv values of shared preferences would yield.
There are no built-in preferences that provide behavior like that. Also no libraries that i know of.
I recommend creating a custom Preference for this. Internally the preference-v7 layouts setttings screen contains a RecyclerView. So you need to override some sort of ViewHolder logic (PreferenceViewHolder)
This could be usefull: http://www.hidroh.com/2015/11/30/building-custom-preferences-v7/
Is there a default control or third party library available in android for creating an auto complete UI control which will allow me to use different values for display text on the control and the actual form value. For example in HTML we have options which will allow us to set different values for value and label for it as shown below.
<select><option value="NJ">New Jersey</option></select>
I have States information in SQLlight database. I want to create an autocomplete UI control which will display the statename in autocomplete options but when selected the form value should be the statecode but not the name.
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.
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.
I want to display contact information in a custom layout. My app lets the user select a contact, then I retrieve key pieces of info on that contact (phone #'s, email addy's, etc). I want to display them to the user so they look grouped logically. Sort of like a series of tables, so phone numbers, then email addys, then organization, etc.
I have a table format that I've been using in a different part of the app where I know the exact number of rows I'm adding and I have defined styles for the rows already. I want to reuse those styles for this data, but android sdk won't allow for you to set the style attribute programmatically.
I could create the tables in code and set all the attributes the same as in my defined styles, but it seems like a lot of extra coding. Any ideas on how I should approach this problem?
Sounds like you need a TableLayout.
To reuse styles externalize them to resource end then you can apply them in multiple places.