I have e project where I have a Edittext from where i have to get input on every keypress or something like every character input.And Have to perform a livesearch. What kind of Listener i have to use to get input for every character input .
Asked
Active
Viewed 3,828 times
0
-
2http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ – Raghunandan Sep 09 '13 at 05:30
4 Answers
1
Do this way
editSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable edit) {
if (edit.length() != 0) {
// Business logic for search here
}
}
});

Biraj Zalavadia
- 28,348
- 10
- 61
- 77
0
An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
Here is a good tutorial:
https://developers.google.com/places/training/autocomplete-android
http://android-er.blogspot.com.au/2010/07/example-of-autocompletetextview.html

nedaRM
- 1,837
- 1
- 14
- 28
0
You need to use 'TextWatcher' as I have already answered here
It will give you result as shown in below images:

Community
- 1
- 1

Mehul Joisar
- 15,348
- 6
- 48
- 57
-
note, however, using EditTexts is not a standart way of filtering ListViews – pskink Sep 09 '13 at 06:24
-
@pskink: kindly have a look at question.as per the requirement,`EditText` is involved. – Mehul Joisar Sep 09 '13 at 08:41
-
kindly have a look at question.as per the requirement, no ListView is involved., so using EditText for filtering ListViews is a bad idea – pskink Sep 09 '13 at 09:15
-
I'm looking more something very similar to this however you can see the results here bring back anything that contains the letter 'm'. How would it be possible to return results that being with letter 'm', since this is the first letter typed - would that need implementing a custom query mechanism ? – Sambuxc May 21 '14 at 15:18
-
@Samuroid: checkout [this](http://stackoverflow.com/questions/14118309/how-to-use-search-functionality-in-custom-list-view-in-android/14119383#14119383) . you need implement `getFilter()` method and also need to replace `data.toLowerCase().startsWith(constraint.toString())` with `data.toLowerCase().contains(constraint.toString())` – Mehul Joisar May 21 '14 at 19:45
-1
Try this..
edittext.addTextChangedListener(new TextWatcher()
{
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String textl = edittext.getText().toString().trim();
}
});

Hariharan
- 24,741
- 6
- 50
- 54