I have a edit text and a listview with all contacts .when i search for the name and it displayes the result, As i type in the name it shows the result like AutoComplete, below is my code
final EditText editTxt = (EditText) findViewById(R.id.txtContName);
editTxt.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
inputName = s.toString();
if(inputName!=null&&!inputName.trim().equals("")){
((Button) findViewById(R.id.btnsearch)).setBackgroundResource(R.drawable.search);
Log.d(TAG, "LoadMoreEntries --> Constants.loadEntries : "
+ Constants.loadEntries);
try {
if (Constants.loadEntries != null) {
Constants.loadEntries.cancel(true);
}
} catch (Exception e) {
Log.e(TAG, "Loading Data-------------------------------", e);
}
Constants.loadEntries = new LoadEntries();
Constants.loadEntries.execute();
}
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
i am facing issue when i am trying to clear the edittext ,All the results should be displayed when the edit text is clear but it is not happening. Any help is appreciated
So I change the code for better formatting. This should solve you’re problem. I don’t know what
Constants.loadEntries = new LoadEntries();
and
Constants.loadEntries.execute();
do, but maybe there can be something wrong too. But try it like the code below:
Better code formatting will definitely help you.