How I can set spinner empty by default? I mean that spinner doesn't have value (empty value) till user choice it.
I usually just provide one fake value with toString empty string. Then the spinner appears empty to the user. Afterwords just perform validation before you finish the activity and if the default value is still on, just show an error, rather than continuing on.
Related
I have a dynamic arraylist that contains String values. I want to match one of its values with AutocompleteText whatever the user has typed/entered. In case the value is not matching with any of the Arraylist values I would like to clear Autocomplete Text.
Couple of Ways I have tried.
Match the typed or user selected value from autocomplete text with list directly without any loop using "contains" method. Didn't achieve the expected result.
Store the values in String[] array from list and loop through it and match it with user input/selection from Autocompletetext. Didn't achieve the result this way too.
Please provide any ideas on how to clear text from autocompletetextview if value is not found?
You did not specify any language that's why i will answer in kotlin
Override onKeyDown method and let's say you will check when enter pressed check if given keycode value equals to KeyEvent.KEYCODE_ENTER
In if block get your text and use an algorithm like below
val arr = intArrayOf(1,2,3) if (textFromTextView !in arr) it means your typed text not in your array and if this condition is true
use autoCompleteTextView.replaceText("") and i hope it will work for you.I never tried but i searched for you.
How to set the string values on spinner prompt?
The process how I am doing is:
I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.
Later, I am trying to set the string value in Spinner prompt
SP_gender is called as Spinner here. In String gender1, I have texts called as "male"
String gender1 = i.getStringExtra("bundle_CusGender");
SP_gender.setPrompt(gender1);
System.out.println("Check bundle_CusGender = : " + gender1);
When I try to print this, I am getting a value as male
System.out: Check bundle_CusGender = : male
How should I set the single text in spinner Android?
Firstly the setPrompt() methods documentation states:
Sets the prompt to display when the dialog is shown.
Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.
Set hint text to be displayed to the user. This should provide
a description of the choice being made.
So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)
For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.
Hello people can someone help.
I have designed a dialog in which I would like to have a field box or some sort that when the dialog is called the TYPE & AMOUNT (link) box's will display the data from database on each item. So for this dialog I have made. The user will click drinks button on the activity before the dialog. And the data will fill theses field boxes once called.
My question is what can I use for this data box caller.
You can use TextView or EditText widget (depending on if you want user to just see or edit the data respectively) and you can pull data from SQLite Database.
in my app i have a spinner and a button below it when i run the program suppose this page is open which contains spinner and a button ,when i dont select any item from spineer it takes first values of spinner by default i want if nothing is selected it contains null value ..... how to do this??? thankss a lot my code is..
HI Saurabh,
I would suggest you to give your first spinner value as "--Select--" or some message. And try to validate in your code, by checking return value of the spinner which should not be the first manual value that you given into the spinner.
You can refer this page
http://developer.android.com/resources/tutorials/views/hello-spinner.html
the parameter "position" records your selected item.so you can use this parameter.
My application has a preference file, "settings", which contains 10 key/value pairs.
The keys act as titles for the user, and the values are URL's
Both the key and the value are changeable by the user e.g. the first setting looks something like "example" with the value "example.com", when a user changes that setting, the key also changes. So the first setting would become "different_example" with the value "different_example.com". All stored under the "settings" preference file.
I have been managing this so far, by opening a dialog containing the current key/value pairs in an ArrayList that has an onItemClickListener that pops up a second dialog containing another ArrayList of the possible key/value pairs. When the new item is clicked, I remove the current setting, add the new one, then re-populate the initial ArrayList with the new settings. This works and allows both the key and value to be simultaneously changed and updated, however it looks awkward with the two dialogs.
I'd like to switch this all over to ListPreferences. As in, have ten different ListPreference items, one for each setting, that when clicked opens the listing of all possible entryValues, and when selected, updates the key from the entry name, and the value from the entry value, and saves this under the same "settings" file. I'm not seeing how to save ListPreferences to a specific file, so that I can call
SharedPreferences settings = getSharedPreferences("settings", 0);
anywhere, though
I've also been looking for some kind of click handler for what to fire when an entry is selected so I can manually update the "settings" file, but not having any luck. Does such a thing exist? Or is there another way for me to do this?
Edit: I can use OnPreferenceChange to manually set the new value, but this doesn't return the value name, e.g. the value used in the human-readable list. Any ideas on how to get that?
See if this can give you a jump start: How do I get preferences to work in Android?
If you customize your ListPreference and come across something like this How to make a Preference not save to SharedPreferences?
Ahh, well this seems incredibly backwards, but what I've done is set each ListPreference to have an onPreferenceChangeListener, and each entryValue for the ListPreference to contain the name as well as the value separated by an arbitrary string. Then in the onPreferenceChange, I can reference the new value (which now also contains the new key) turn it into a String[] split at the arbitrary separator, then assign the String[] 0 index as the new key, and the 1 index as the new value by using SharedPreferences.Editor after removing the original setting.
Unless there's some way to return the Entry name from the ListPreference's entryValues array, or to specify ListPreference to save to a specific settings file, neither of which is documented, then this will probably be the best solution for me.