How to Show search suggestion in Autocomplete for android? - android

As a user when I start typing into the search field I want to see some autocomplete options based on matching terms in the paragraph(String) so that I don't have to type really long terms using a tiny phone keyboard.
Note:
The Suggestion will come from particular content or String

The following link is for the Android Developers forum that should get you started along. Link : https://developer.android.com/reference/android/widget/AutoCompleteTextView.html
The example as provided in the link for creating text view which suggests various countries names while the user is typing:
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
//initialise the adapter for give n array of strings to be searched with
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView autotextView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
//set the adapter for the Autocomplete TextView
autotextView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}

Try this, Make a layout containing autoCompleteTextView
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
then in java code list all the suggestions in the array,
String[] suggestions ={"Android","java"};
//or get it via array.xml of res, using
//String[] suggestions = getResources().getStringArray(R.array.suggarray);
text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,suggestions);
text.setAdapter(adapter);
text.setThreshold(1);

Related

How to implement AutoCompleteTextView with several chosen options?

Web application which uses Bootstrap, has input area like this.
Is there any library to implement EditText like this in Android?
Yes, the completed bubbles are called "chips" in Android. A full example of a working solution is far too detailed for an answer here, but this is just one library that I have used with success.
https://github.com/splitwise/TokenAutoComplete/
And one more, for safe measure
https://github.com/klinker41/android-chips
Use AutoCompleteTextView
Offical example:
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
https://developer.android.com/reference/android/widget/AutoCompleteTextView.html

How to populate values when I try to enter values in EditText field in Android?

I've following requirement and Since I'm new to this Android stuff, I'm not able to figure it out.
I've two Edit text fields for a driverName and a vehicleNumber. But these values shouldn't be new i.e When I try to enter driverName in particular EditText field, I should get all the driverNames populated so that I can choose one them. Same for vehicleNumber too.
For this I already have data of driverName and Vehicle Number But my problem is how to populate them while entering in fields ??? Any good answer will be appreciated :)
Thank You.
You should go AutoCompleteTextView as What M D suggested. Example is
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}

how to show possible matching suggestions for text being typed in an edittext?

i'm creating an Application where there is a part where user needs to enter the state,city and district in an Edittext.
while entering the state I need to show some possibly matching suggestions with the letters that are typed in the edittext.
I have searched a lot and couldnt find anything useful as per my requirements..
So how do i go about this?? the suggestions of can come from a sqlite database table... if anybody knows any good example or can guide me through the coding please help...
i have no idea how to do it...
use autocomplete textview and then get your country/state list and set in adapter.
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
setThreshold(int threshold)
Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.
AutoCompleteTextView might help you
try it out here

Text filtering in listview from Edittext Android

I have a list of cities(around 2500 of them). I want the user to get auto suggestions when he types in the edittextbox from that list. How is this achieved? I have searched Google through and through but cannot find any tutorial about this. Would really appreciate any help.
Thanks.
You should use AutoCompleteTextView to achieve this.
The following code snippet shows how to create a text view which suggests various countries names while the user is typing:
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
Use AutoCompleteTextview, here is a tutorial from the development site (bottom of the page). http://developer.android.com/guide/topics/ui/controls/text.html
You can use "Filter" for searching from your other list.
Implement your own filter [MyFilter extends Filter] and override "FilterResults performFiltering(CharSequence prefix)" and "void publishResults(CharSequence constraint,FilterResults results)" methods to implement your own searching logic on your own data (country list).
Add a getMyFilter() method in your adapter which will return a "new myFilter"
Add a "TextWatcher" to your "EditText"
Inside "onTextChanged()" method of the TextWatcher, get your filter by calling myAdapter.getMyFilter()". On that filter, call "myFilter.filter(myTypedString)".
After filtering "void publishResults(CharSequence constraint,FilterResults results)" method will get called. Inside that, change your actual adapter data to refresh your UI.

Android: Finding Similar Words

In an EditText functioning as a Search box, how do I find a similar word
Can anyone help?
Thanks
Rocki
AutocompletetextView is best one for do this: here is the link: http://www.androidaspect.com/2012/06/autocompletetextview-example.html
you have two options
AutoCompleteTextView
check this AutoCompleteTextView
Edit text with addTextChangedListener
Check this List View with easy searching with EditText
Follow AutoCompleteTextView documentation
AutoCompleteTextView is an editable text view that shows completion
suggestions automatically while the user is typing.
Also read about ArrayAdapter
A concrete BaseAdapter that is backed by an array of arbitrary
objects.
And try the following example from documentation
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}

Categories

Resources