Question

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

Was it helpful?

Solution

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"
>

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top