I want to populate my quick search box using a web service. I have a web service in place which pulls the search data from a web server to put into a string array. I want the show that list of data as the user types into the search dialog. I believe the default search dialog is a simple EditText. How do I make it an`AutoCompleteTextView to and populate that with the string array containing my data?
First you have to parse the data from the webservice, then store the Values/data in a String
Example: CricketTeams
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, CricketTeams);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
} }
where Cricket teams will be having the data from your web service.
More detailed Example Here
Related
I want to show only one parameter from object(s) found using AutoCompleteTextView. I have list of custom items and I'm using this list in ArrayAdapter which is used in my AutoCompleteTextView. But as I find item by typing something to AutoCompleteTextView, only object as whole is shown (Object type and some identifier), but I want to show just Objects attribute "name" which is a String.
The way i'd go about this is making a separate arraylist with all the names inside of it. Display that and get the user to chose from there, once they have use the index to find the object in the other list.
Initiate new string array
String[] data = new String[1]); // terms is a List<String>
for(int i=0;i<=1;i++){ //only the 1st position of ur data getting inserted
data[0]=s.get(i).toString();
}
ArrayAdapter<?> adapter = new ArrayAdapter<Object>(activity, android.R.layout.simple_dropdown_item_1line, data);
keywordField.setAdapter(adapter); // keywordField is a AutoCompleteTextView
I have login activity where username is read from editText field. How can I make such an functionality to suggest usernames that have been already logged in from the same device?
Use an AutoCompleteTextView instead of normal EditText
Save previous usernames in a sqlite db and then pull from that for the AutoCompleteTextView.
Here is some example code that should get you started.
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.autocomplete_usernames);
String[] usernames = db.getUsernames();
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames);
textView.setAdapter(adapter);
For fast and easy implementation, you can use Android SharedPreferences in which you can easily save your previous input string.
Read the documentation. It is well explained.
But if you want to save an array/arraylist, you can use also SharedPreferences.
Read this answer
I have a multiautocomplete textview which autocompletes when the user types something on the box with respect to the data query on the ContactsContracts using content resolver. But i wanted to display the name and number on one list.
here is the code
name_Val = (String[]) c_Name.toArray(new String[c_Name.size()]);
phone_Val= (String[]) c_Number.toArray(new String[c_Name.size()]);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),R.layout.custom_dropdown, name_Val);
txtPhoneNo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
txtPhoneNo.setAdapter(adapter);
Unfortunately it only displays the name. I wanted to display the number after the the contacts name.
you should use the custom adapter or a simple adapter with custom view
I want to create a AutoCompleteTextView in android. The problem is that I want to show whole list of data when user selects AutoCompleteTextView and start filtering data as user types the letters.Please help me in doing this.
Well here is an way how you can do that,
declare an String array -
String[] array = new String[]{"first","second","third","fourth"};
Now, initialize the Adapter with the source.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,array);
Finally fetch the AutoCompleteTextView id from your xml and set the adapter.
AutoCompleteTextView mView = (AutoCompleteTextView)
findViewById(R.id.myAutoTextView);
mView.setAdapter(adapter);
I created a list view which extends ListActivity and I have a search field at the top of the page
but I don't know how to write it , I want a search like search contact (type just only 1 char and listview will change, don't have to press any button)
please give me some example code
thanks
I think you should see this
If you are currently using a CursorAdapter to display the List, than you can create a custom CursorAdapter which does filtering automatically as you type keys. The following webpage provides an excellent example of this: http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/
Good luck!
Create a AutoCompleteTextView in your Layout,then put this in your class file,
AutoCompleteTextView txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, name_Val);
txtPhoneNo.setAdapter(adapter);
where name_Val is the String Array that contains "DATA"