AutoCompleteTextView adapter returning old values - android

I implemented an AutoCompleteTextView where the data is updated from the server every time the user enters a new text input. It works well. However, every time I enter a new query, the previous results are displayed until the new result set is updated.
My guess is that it displays the currently queried results until the backend responds with the new search results. Is there a way to clear the current results?
Activity code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_test);
actv = (AutoCompleteTextView) findViewById(R.id.actv);
actv.setThreshold(1);
actv.setAdapter(new SearchSuggestionsAdapter(this, actv.getText().toString()));
Custom adapter:
public class SearchSuggestionsAdapter extends ArrayAdapter<String> {
List<String> types = new ArrayList<>();
protected static final String TAG = "SuggestionAdapter";
private List<String> suggestions;
private Context context;
public SearchSuggestionsAdapter(Activity context, String nameFilter) {
super(context, android.R.layout.simple_dropdown_item_1line);
suggestions = new ArrayList<String>();
this.context = context;
}
#Override
public int getCount() {
return suggestions.size();
}
#Override
public String getItem(int index) {
return suggestions.get(index);
}
#Override
public Filter getFilter() {
Filter myFilter = new Filter() {
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
//Get new results from backend
//searchItemsFromServer is the method that returns the data
//new data is successfully sent. no problem there
List<String> new_suggestions = searchItemsFromServer(constraint.toString());
suggestions.clear();
for (int i = 0; i < new_suggestions.size(); i++) {
suggestions.add(new_suggestions.get(i));
}
filterResults.values = suggestions;
filterResults.count = suggestions.size();
}
return filterResults;
}
#Override
protected void publishResults(CharSequence contraint,
FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
};
return myFilter;
}
}
Thank you in advance!

Change your code to your activity to this
SearchSuggestionsAdapter searchSuggestionsAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_test);
searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, actv.getText().toString());
actv = (AutoCompleteTextView) findViewById(R.id.actv);
actv.setThreshold(1);
actv.setAdapter(searchSuggestionsAdapter);
actv.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
searchSuggestionsAdapter.clear();
}
}
});
}
Add the following code to your SearchSuggestionsAdapter
/**
* Create list and notify recycler view
*/
public void clear() {
if (suggestions != null) {
suggestions.clear();
notifyDataSetChanged();
}
}

actv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
suggestionAdapter.clear;
}
});
When user click on autocomplete remove the old adapter. But for this you need to define suggesstionAdapter first. and every time update this adapter and set it to autocomplete

Clear suggestion before filtering. Call adapter.clear();
Add new method in adapter
public void clear() {
suggestions.clear();
notifyDataSetChanged();
}

Related

How to get autocompletetextview id?

I follow this example to use autocmpletetextview in my project,i want to get id when user select any item,can anyone tell how to get id..
following is json response..so if click on ab then i want to get 1,if i click on abc i want to get 2..
MainActivity
public class MainActivity extends Activity {
private AutoCompleteTextView acTextView;
private String idtest;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acTextView = (AutoCompleteTextView) findViewById(R.id.autoComplete);
final SuggestionAdapter adapter=new SuggestionAdapter(this, acTextView.getText().toString());
acTextView.setAdapter(adapter);
acTextView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
JsonParse jps=new JsonParse();
/* List<SuggestGetSet> list =jps.getParseJsonWCF(acTextView.getText().toString());
for(int i = 0;i<list.size();i++)
{
if(list.get(i).getName().equals(acTextView.getText().toString()))
idtest=list.get(position).getId();
}
*/
SuggestGetSet selectedSuggestGetSet =
adapter.getAllUpdatedSuggestion().get(position);
Toast.makeText(getApplicationContext(), selectedSuggestGetSet+acTextView.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
adapter
public class SuggestionAdapter extends ArrayAdapter<String> {
protected static final String TAG = "SuggestionAdapter";
public List<String> suggestions;
private List<SuggestGetSet> new_suggestions;
public SuggestionAdapter(Activity context, String nameFilter) {
super(context, android.R.layout.simple_dropdown_item_1line);
suggestions = new ArrayList<String>();
}
#Override
public int getCount() {
return suggestions.size();
}
#Override
public String getItem(int index) {
return suggestions.get(index);
}
#Override
public Filter getFilter() {
Filter myFilter = new Filter() {
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
JsonParse jp=new JsonParse();
if (constraint != null) {
// A class that queries a web API, parses the data and
// returns an ArrayList<GoEuroGetSet>
new_suggestions =jp.getParseJsonWCF(constraint.toString());
suggestions.clear();
for (int i=0;i<new_suggestions.size();i++) {
suggestions.add(new_suggestions.get(i).getName());
}
// Now assign the values and count to the FilterResults
// object
filterResults.values = suggestions;
filterResults.count = suggestions.size();
}
return filterResults;
}
#Override
protected void publishResults(CharSequence contraint,
FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
};
return myFilter;
}
public List<SuggestGetSet> getAllUpdatedSuggestion(){
return this.new_suggestions;
}
}
response
{"results":[{"id":"1","name":"ab"},{"id":"2","name":"abc"},{"id":"3","name":"bc"},{"id":"4","name":"bcd"},{"id":"5","name":"cd"},{"id":"6","name":"cde"},{"id":"7","name":"ef"},{"id":"8","name":"efg"},{"id":"9","name":"hi"},{"id":"10","name":"hig"},{"id":"11","name":"jk"},{"id":"12","name":"jkl"},{"id":"13","name":"mn"},{"id":"14","name":"mno"},{"id":"15","name":"pq"},{"id":"16","name":"pqr"},{"id":"17","name":"st"},{"id":"18","name":"stu"},{"id":"19","name":"vw"},{"id":"20","name":"vwx"},{"id":"21","name":"yz"},{"id":"22","name":"yza"}]}
Put one method in adapter
public Int getItemId(int index) {
return suggestions.get(index).getId();
}
Then access it in onItemClick. You will getId from there by
adapter.getItemId(position);
How to get id of autocompletetextview item?
new_suggestions contains all items which want to get on ListView item click. so declare it outside getFilter method for access from other class:
private List<String> suggestions;
private List<SuggestGetSet> new_suggestions ;
....
new_suggestions initilize it inside getFilter method:
...
new_suggestions =jp.getParseJsonWCF(constraint.toString());
suggestions.clear();
...
Now create a method inside SuggestionAdapter :
public List<SuggestGetSet> getAllUpdatedSuggestion(){
return this.new_suggestions;
}
and finally inside onItemClick call getAllUpdatedSuggestion method:
final SuggestionAdapter adapter=new SuggestionAdapter(this,
acTextView.getText().toString())
acTextView.setAdapter(adapter);
and in onItemClick method:
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
SuggestGetSet selectedSuggestGetSet =
adapter.getAllUpdatedSuggestion().get(position);
}
selectedSuggestGetSet will contains selected item name and id
Change your suggestions list to public :
public List<String> suggestions;
And then get the desired id in your itemClick method :
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
your id = YourAdapter.suggestions[position].id;
}
check this
List<SuggestGetSet> new_suggestions = jp.getParseJsonWCF(constraint.toString());
and make one with private List<SuggestGetSet> new_suggestions; in your adapter

AutoCompleteTextView not populating with selected item

I've done a fair bit of Google-fu but I cannot figure out what's wrong. Filtering works, the drop down list appears. But the AutoCompleteTextView doesn't populate with the selected item! Can anyone help?
I set a custom adapter to my AutoCompleteTextView that shows a custom layout.
actv = (AutoCompleteTextView) root.findViewById(R.id.actv);
actv.setAdapter(new MyCustomAutoCompleteAdapter(getActivity()));
Here are the important parts MyCustomAutoCompleteAdapter code:
public class MyCustomAutoCompleteAdapter extends ArrayAdapter<String>
implements Filterable {
Context mContext;
private ArrayList<String> resultList = new ArrayList<>();
public MyCustomAutoCompleteAdapter(Context context) {
// is this the correct way to super?
super(context, R.layout.my_custom_layout);
mContext = context;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
...
return convertView;
}
#Override
public int getCount() {
return resultList.size();
}
#Override
public String getItem(int index) {
return resultList.get(index);
}
#Override
public Filter getFilter() {
Filter filter = new Filter() {
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
// Retrieve the autocomplete results.
resultList = doPlacesSearchQuery(constraint.toString());
// Assign the data to the FilterResults
filterResults.values = resultList;
filterResults.count = resultList.size();
}
return filterResults;
}
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
}
else {
notifyDataSetInvalidated();
}
}};
return filter;
}
private ArrayList<String> doPlacesSearchQuery(String query) {
ArrayList<String> retList = new ArrayList<>();
... // do my API call here
return retList;
}
}
I found my answer; I was indeed using the wrong super constructor.
public MyCustomAutoCompleteAdapter(Context context) {
super(context,
R.layout.my_custom_layout,
R.id.id_of_textview_in_my_custom_layout);
mContext = context;
}

No results when using a custom ArrayAdapter and Filter

I have a custom ArrayAdapter like in this code:
public class UtenteAdapter extends ArrayAdapter<Utente> implements Filterable {
private Context context;
private ArrayList<Utente> utenti;
private ArrayList<Utente> utentiFiltrati;
private FiltroPersonalizzato filtro;
public UtenteAdapter(Context context, ArrayList<Utente> utenti) {
super(context, R.layout.riga_utente, utenti);
this.context=context;
this.utenti=utenti;
utentiFiltrati = new ArrayList<Utente>();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//omitted..
return riga;
}
#Override
public void notifyDataSetChanged(){
super.notifyDataSetChanged();
}
#Override
public Filter getFilter() {
if (filtro == null) {
filtro = new FiltroPersonalizzato();
}
return filtro;
}
private class FiltroPersonalizzato extends Filter {
#Override
protected FilterResults performFiltering(CharSequence prefix) {
FilterResults risultato = new FilterResults();
ArrayList<Utente> i = new ArrayList<Utente>();
if (prefix!= null && prefix.toString().length() > 0) {
// use the initial values !!!
for (int index = 0; index < utenti.size(); index++) {
Utente si = utenti.get(index);
final int length = prefix.length();
// if you compare the Strings like you did it will never work as you compare the full item string(you'll have a match only when you write the EXACT word)
// keep in mind that you take in consideration capital letters!
if(si.getNome().toLowerCase().substring(0, length).compareTo(prefix.toString().toLowerCase()) == 0){
i.add(si);
}
}
risultato.values = i;
risultato.count = i.size();
}
else{
// revert to the old values
synchronized (utentiFiltrati){
risultato.values = utenti;
risultato.count = utenti.size();
}
}
return risultato;
}
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
utentiFiltrati = (ArrayList<Utente>)results.values;
notifyDataSetChanged();
}
}
}
I have a SearchView and I want to filter the rows by name but I have no results after filtering. I am sure that I have results(from debugging) but if I call filter from my ListFragment I can't see my result:
#Override
public boolean onQueryTextSubmit(String query) {
adapter.getFilter().filter(query);
return true;
}
I update my ArrayAdapter from the ListFragment like this:
private void setListaUtenti(){
if(getListAdapter()==null){
// creo l'adapter
adapter=new UtenteAdapter(
getActivity(),
utenti);
setListAdapter(adapter);
} else{
adapter.notifyDataSetChanged();
}
}
Why don't I see the results of the filtering operation?
i have a searchview and i want filter row by name but i have no
result.
It's normal that you don't get a result as in the publishResults() callback of the Filter you assign the results to the utentiFiltrati list and call notifyDataSetChanged(). This will do nothing as your adapter is based on the utenti list, the one you pass to the super class constructor. Make the following changes:
public UtenteAdapter(Context context, ArrayList<Utente> utentiValues) {
super(context, R.layout.riga_utente, utentiValues);
this.context=context;
this.utentiFiltrati = utentiValues;
utenti = new ArrayList<Utente>(utentiValues);
}
// ...
FilterResults risultato = new FilterResults();
ArrayList<Utente> i;
if (prefix == null || prefix.toString().length() == 0) {
// the contract of a Filter says that you must return all values if the
// challenge string is null or 0 length
i = new ArrayList<Utente>(utenti);
} else {
i = new ArrayList<Utente>();
// use the list that contains the full set of data
for (int index = 0; index < utenti.size(); index++) {
Utente si = utenti.get(index);
final int length = prefix.length();
if(si.getNome().toLowerCase().substring(0, length).compareTo(prefix.toString().toLowerCase()) == 0){
i.add(si);
}
}
//...
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
utentiFiltrati = (ArrayList<Utente>)results.values;
notifyDataSetChanged();
}

List View Filter Android

I have created a list view in android and I want to add edit text above the list and when the user enter text the list will be filtered according to user input
can anyone tell me please if there is a way to filter the list adapter in android ?
Add an EditText on top of your listview in its .xml layout file.
And in your activity/fragment..
lv = (ListView) findViewById(R.id.list_view);
inputSearch = (EditText) findViewById(R.id.inputSearch);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products);
lv.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MainActivity.this.adapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
#Override
public void afterTextChanged(Editable arg0) {}
});
The basic here is to add an OnTextChangeListener to your edit text and inside its callback method apply filter to your listview's adapter.
EDIT
To get filter to your custom BaseAdapter you"ll need to implement Filterable interface.
class CustomAdapter extends BaseAdapter implements Filterable {
public View getView(){
...
}
public Integer getCount()
{
...
}
#Override
public Filter getFilter() {
Filter filter = new Filter() {
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
arrayListNames = (List<String>) results.values;
notifyDataSetChanged();
}
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList<String> FilteredArrayNames = new ArrayList<String>();
// perform your search here using the searchConstraint String.
constraint = constraint.toString().toLowerCase();
for (int i = 0; i < mDatabaseOfNames.size(); i++) {
String dataNames = mDatabaseOfNames.get(i);
if (dataNames.toLowerCase().startsWith(constraint.toString())) {
FilteredArrayNames.add(dataNames);
}
}
results.count = FilteredArrayNames.size();
results.values = FilteredArrayNames;
Log.e("VALUES", results.values.toString());
return results;
}
};
return filter;
}
}
Inside performFiltering() you need to do actual comparison of the search query to values in your database. It will pass its result to publishResults() method.
Implement your adapter Filterable:
public class vJournalAdapter extends ArrayAdapter<JournalModel> implements Filterable{
private ArrayList<JournalModel> items;
private Context mContext;
....
then create your Filter class:
private class JournalFilter extends Filter{
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
List<JournalModel> allJournals = getAllJournals();
if(constraint == null || constraint.length() == 0){
result.values = allJournals;
result.count = allJournals.size();
}else{
ArrayList<JournalModel> filteredList = new ArrayList<JournalModel>();
for(JournalModel j: allJournals){
if(j.source.title.contains(constraint))
filteredList.add(j);
}
result.values = filteredList;
result.count = filteredList.size();
}
return result;
}
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results.count == 0) {
notifyDataSetInvalidated();
} else {
items = (ArrayList<JournalModel>) results.values;
notifyDataSetChanged();
}
}
}
this way, your adapter is Filterable, you can pass filter item to adapter's filter and do the work.
I hope this will be helpful.
In case anyone are still interested in this subject, I find that the best approach for filtering lists is to create a generic Filter class and use it with some base reflection/generics techniques contained in the Java old school SDK package. Here's what I did:
public class GenericListFilter<T> extends Filter {
/**
* Copycat constructor
* #param list the original list to be used
*/
public GenericListFilter (List<T> list, String reflectMethodName, ArrayAdapter<T> adapter) {
super ();
mInternalList = new ArrayList<>(list);
mAdapterUsed = adapter;
try {
ParameterizedType stringListType = (ParameterizedType)
getClass().getField("mInternalList").getGenericType();
mCompairMethod =
stringListType.getActualTypeArguments()[0].getClass().getMethod(reflectMethodName);
}
catch (Exception ex) {
Log.w("GenericListFilter", ex.getMessage(), ex);
try {
if (mInternalList.size() > 0) {
T type = mInternalList.get(0);
mCompairMethod = type.getClass().getMethod(reflectMethodName);
}
}
catch (Exception e) {
Log.e("GenericListFilter", e.getMessage(), e);
}
}
}
/**
* Let's filter the data with the given constraint
* #param constraint
* #return
*/
#Override protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
List<T> filteredContents = new ArrayList<>();
if ( constraint.length() > 0 ) {
try {
for (T obj : mInternalList) {
String result = (String) mCompairMethod.invoke(obj);
if (result.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
filteredContents.add(obj);
}
}
}
catch (Exception ex) {
Log.e("GenericListFilter", ex.getMessage(), ex);
}
}
else {
filteredContents.addAll(mInternalList);
}
results.values = filteredContents;
results.count = filteredContents.size();
return results;
}
/**
* Publish the filtering adapter list
* #param constraint
* #param results
*/
#Override protected void publishResults(CharSequence constraint, FilterResults results) {
mAdapterUsed.clear();
mAdapterUsed.addAll((List<T>) results.values);
if ( results.count == 0 ) {
mAdapterUsed.notifyDataSetInvalidated();
}
else {
mAdapterUsed.notifyDataSetChanged();
}
}
// class properties
private ArrayAdapter<T> mAdapterUsed;
private List<T> mInternalList;
private Method mCompairMethod;
}
And afterwards, the only thing you need to do is to create the filter as a member class (possibly within the View's "onCreate") passing your adapter reference, your list, and the method to be called for filtering:
this.mFilter = new GenericFilter<MyObjectBean> (list, "getName", adapter);
The only thing missing now, is to override the "getFilter" method in the adapter class:
#Override public Filter getFilter () {
return MyViewClass.this.mFilter;
}
All done! You should successfully filter your list - Of course, you should also implement your filter algorithm the best way that describes your need, the code bellow is just an example.. Hope it helped, take care.

Fetch AutoCompleteTextView suggestions from service in separate thread

For my AutoCompleteTextView I need to fetch the data from a webservice. As it can take a little time I do not want UI thread to be not responsive, so I need somehow to fetch the data in a separate thread. For example, while fetching data from SQLite DB, it is very easy done with CursorAdapter method - runQueryOnBackgroundThread. I was looking around to other adapters like ArrayAdapter, BaseAdapter, but could not find anything similar...
Is there an easy way how to achieve this? I cannot simply use ArrayAdapter directly, as the suggestions list is dynamic - I always fetch the suggestions list depending on user input, so it cannot be pre-fetched and cached for further use...
If someone could give some tips or examples on this topic - would be great!
With the approach above, i also had those problems when typing very fast. I guess it´s because the filtering of the results is done asynchronously by the filter class, so there can be problems when modifying the ArrayList of the Adapter in the ui thread while filtering is done.
http://developer.android.com/reference/android/widget/Filter.html
However with following approach everything worked fine.
public class MyActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyAdapter myAdapter = new MyAdapter(this, android.R.layout.simple_dropdown_item_1line);
AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
acTextView.setAdapter(myAdapter);
}
}
public class MyAdapter extends ArrayAdapter<MyObject> {
private Filter mFilter;
private List<MyObject> mSubData = new ArrayList<MyObject>();
static int counter=0;
public MyAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
setNotifyOnChange(false);
mFilter = new Filter() {
private int c = ++counter;
private List<MyObject> mData = new ArrayList<MyObject>();
#Override
protected FilterResults performFiltering(CharSequence constraint) {
// This method is called in a worker thread
mData.clear();
FilterResults filterResults = new FilterResults();
if(constraint != null) {
try {
// Here is the method (synchronous) that fetches the data
// from the server
URL url = new URL("...");
URLConnection conn = url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while ((line = rd.readLine()) != null) {
mData.add(new MyObject(line));
}
}
catch(Exception e) {
}
filterResults.values = mData;
filterResults.count = mData.size();
}
return filterResults;
}
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence contraint, FilterResults results) {
if(c == counter) {
mSubData.clear();
if(results != null && results.count > 0) {
ArrayList<MyObject> objects = (ArrayList<MyObject>)results.values;
for (MyObject v : objects)
mSubData.add(v);
notifyDataSetChanged();
}
else {
notifyDataSetInvalidated();
}
}
}
};
}
#Override
public int getCount() {
return mSubData.size();
}
#Override
public MyObject getItem(int index) {
return mSubData.get(index);
}
#Override
public Filter getFilter() {
return mFilter;
}
}
EDITED: Added naive way to avoid the dropdown showing when you click a suggestion.
I do something like this in my app:
private AutoCompleteTextView mSearchbar;
private ArrayAdapter<String> mAutoCompleteAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
mAutoCompleteAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
mSearchbar = (AutoCompleteTextView) findViewById(R.id.searchbar);
mSearchbar.setThreshold(3);
mSearchbar.setAdapter(mAutoCompleteAdapter);
mSearchbar.addTextChangedListener(new TextWatcher() {
private boolean shouldAutoComplete = true;
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
shouldAutoComplete = true;
for (int position = 0; position < mAutoCompleteAdapter.getCount(); position++) {
if (mAutoCompleteAdapter.getItem(position).equalsIgnoreCase(s.toString())) {
shouldAutoComplete = false;
break;
}
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
if (shouldAutoComplete) {
new DoAutoCompleteSearch().execute(s.toString());
}
}
}
}
private class DoAutoCompleteSearch extends AsyncTask<String, Void, ArrayList<String>> {
#Override
protected ArrayList<String> doInBackground(String... params) {
ArrayList<String> autoComplete = new ArrayList<String>();
//do autocomplete search and stuff.
return autoComplete;
}
#Override
protected void onPostExecute(ArrayList<String> result) {
mAutoCompleteAdapter.clear();
for (String s : result)
mAutoCompleteAdapter.add(s);
}
}
had the same solution except that the problem is that everything is just fine ( variables are updated when i debug) but the autocomplete fills weirdly as in
when i type sco it has the results but does not show in list
but when i backspace it shows the result for sco. In debug all the variables are updated which only tells me that the UI is not getting updated for AutoCompleteTextView. as when i backspace it is triggered for update and then it shows earlier computer list then it(in the mean time it updates it with the new list items for new search string.
anyone ran into this problem?

Categories

Resources