Here is my scenario: I've got a database, where 2 columns are interesting for me. I now created an autocompletetextview where the adapter gehts via SQL the entries of one column.
So far... so good, but what i actually want is, that if the user types sth. into the autocompletefield i notice this and fetch the text. Via SQL I now want to get everey Entry of column 2 where the value of column 1 is contained in the entered text. And this List should be displayed in the adapter. In other words I filter the data by myself via sql but i want them to be shown in the adapter.
The problem is, that the adapter only shows the entries which start with the text in the autocompletefield but I want to show the adapter anytime, as already saied: I filter the data by myself I just want the adapter to display them.
Any ideo how to solve this? Is the AutocompleteTextView the right item to use?
I also thought about using a simple Spinner... but when using a spinner there are 2 main problems. first I would have to make him editable. and second I would need a dropdown instead of the "popup". ...
Another idea of mine to solve this issue is to write an own filter for the autocomplete field... but i've never down this so far and I also couldn't found any examples in the internet to do so.
thanks for your help
I changed the ArrayAdapter method of spinner and i got my custom Spinner.
just change the parameter of this method like
Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(This,R.array.statename,R.layout.mylayout);
spinner.setAdapter(adp);
In Which the mylayout file contains
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/spinnerTarget"
android:textColor="#FF8B1500"
android:gravity="center"
>
You can use autocompleteTextView and set its adapter to your values from SQLite or from String Array as shown below:
String values[]= {"Orange","Apple","Pineapple"};
AutoCompleteTextView text=(AutoCompleteTextView)findViewById(R.id.a1);
text.setAdapter(new ArrayAdapter<String>
(this,android.R.layout.simple_dropdown_item_1line,values));
for more information on it go to developers site
Related
I have three spinners in my activity. based on the item selected in first spinner the second spinner is populated with a new set of values. till here the program works fine. now i want that based on selection of item on 2nd spinner the third spinner should be populated. but i am not able to achieve this.
As you can do on the first spinner and second spinner. use secondSpinner.setOnItemSelectedListener(new OnItemSelectedListener() and then create and setAdapter to the third spinner.
see this question might help
how do I set the spinner value to null or to a hint when it is not on click..? Because when I set spinner's adapter it appears in the spinner textfield even Im not selecting a specific dropdown item.
You can insert first item with "" (empty string) value in your ArrayList or Array.
If there is any data in the adapter in the spinner then it will show that data. So in this case it is not possible to show empty spinner.
In your case My suggestion is, use a entry like none/no selection in your spinner at the very first index. So that it will automatically show that. Also user can select no selection option from the spinner also.
Possible duplicate.
You could create the illusion of the spinner by styling a button like below.
android:background="#android:drawable/btn_dropdown"
see [here] for alternatives. (Android: Spinner hint)
On the onItemSelected:
((TextView)view).setText(null);
By using this, Spinner will not show any default value.
I'm wondering if there's a setText() method in spinners? What I want to do is display the selected item in a spinner (it's saved via sharedpreferences.) so the next time, the user displays the saved data, it should display in the spinner. How can I do that? I already know how to do it an edittext like this : age.setText(age);
But wondering how to show it in spinners.
There is no such method in Spinner class.
You need to implement a SpinnerAdapter which will be responsible for creating the items of the Spinnerand attach it via the setAdapter() method.
The official Spinners guide may help you: http://developer.android.com/guide/topics/ui/controls/spinner.html
I am just thinking to create like below in spinner, but i am not sure how to make it work
Fruits (heading unclickable)
Apple
Mango
Orange
Cars (heading unclickable)
BMW
Lenova
Is that possible in Spinner or if you know any other method to create like this, then it would be great.
I am getting those details from the local database. Heading from one table and records from one table.
I am looking for any example or solution.
Thanks for your help guys.
After long time i found a way to do this. I achieved by combining a Button and Expandable ListView. What i have done is i created a button like spinner. OnClick I launched a popup Activity with Expandable list view in it by calling startActivityForResult() which returns the selected value. Finally i replaced the button text with the selected value.
If you looking for Expandable ListView Tutorial you can click below link.
(http://androidtrainningcenter.blogspot.co.uk/2012/07/android-expandable-listview-simple.html).
Take a look at the Spinner example in the Hello Views tutorial. They accomplish this by using a TextView for the heading, and the spinner for the selectable list of options.
I have a question about adding spinner to listview header:
How should I get a spinner to showup in the listview header.
How to dynamically populate values in this spinner based on values in the listview.
Description:
I have a listview which populates values from an XML file (placed on the net). This list can be huge based on user selection on previous screen(s) and/ or data in XML file.
I would like to add a spinner at the top of the listview such that user will have an option to perform filter action/ sort action. How should this be achieved?
For example:
If my app shows a list of books available in the library. The spinner should help user to:
1. Sort alphabetically based on book title
2. Sort alphabetically based on author name
3. Filter out only books related to 'War'
4. Filter out only books related to 'History'
5. Filter out only books related to 'Science'
When I am populating the listview, the XML provides details such as 'Type of Book', 'Author', 'Title', etc.
Question is, how do I place a spinner at the top & populate values like, the types (War, History, Crime, etc.) to the Spinner based on the list of books in the listview.
I have tried to be as descriptive as possible. If any further details required, please let me know.
Any help will be highly appreciated.
Thanks a Bunch!
For putting the spinner above the ListView, check this method out: http://developer.android.com/reference/android/widget/ListView.html#addHeaderView%28android.view.View%29
Or you could put a custom title-layout thing about the ListView in the parent layout for the Activity.
More ListView help: http://www.vogella.de/articles/AndroidListView/article.html#listview_overview
As far as populating the spinner, you can have the spinner set to whichever values you want. In the example online( http://developer.android.com/resources/tutorials/views/hello-spinner.html ):
String[] myValues = // Put code here for the values and size of array you want.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, YOUR_STRING_ARRAY_VARIABLE_HERE, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
It is your job as a programmer to figure out how to take which item is selected in the spinner and make changes to the listView. To update values in a listview check this out: update listview dynamically with adapter
One solution and how I would do it is make a custom Java class for an Entry so that you can take in the XML file and give each entry instance variables or characteristics to sort them by. Then using this data model, make a class EntryList or EntryArray that can handle the sorting of your Entry data objects. Then have a toStringArray() method that will return a string array. In this way you hold on to the data, and allow all of the sorting you need. Each time the spinner is clicked, the corresponding method in EntryList or EntryArray is called, a new String array is put in the adapter, and the user sees the new sorted list.
This was probably a lot to digest, so read up on all of the links, and see if you can implement it. Cheers!