I would like to show loading indicator in AutoCompleteTextView while loading data from web-service. Preferably it should be shown on right side of autocomplete (f.i. animation like in progress control - spinning wheel). How this can be done?
Defines the hint view displayed in the drop down menu. Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu.
If you want to get suggestions , when you type in an editable text field , you can do this via AutoCompleteTextView. It provides suggestions automatically when 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.
A AutoCompleteTextView is a view that is similar to EditText, except that it shows a list of completion suggestions automatically while the user is typing. The list of suggestions is displayed in drop down menu. The user can choose an item from there to replace the content of edit box with.
In android, we can create an AutoCompleteTextView control in two ways either manually in an XML file or create it in the Activity file programmatically. First we create a new project by following the below steps: Click on File, then New => New Project. After that include the Kotlin support and click on next.
I would like to show loading indicator in AutoCompleteTextView while loading data from web-service.
Put a ProgressBar
with an indeterminate look on the right of the widget and extend the AutoCompleTextView
class like this:
public class AutoCompleteLoadding extends AutoCompleteTextView {
private ProgressBar mLoadingIndicator;
public void setLoadingIndicator(ProgressBar view) {
mLoadingIndicator = view;
}
@Override
protected void performFiltering(CharSequence text, int keyCode) {
// the AutoCompleteTextview is about to start the filtering so show
// the ProgressPager
mLoadingIndicator.setVisibility(View.VISIBLE);
super.performFiltering(text, keyCode);
}
@Override
public void onFilterComplete(int count) {
// the AutoCompleteTextView has done its job and it's about to show
// the drop down so close/hide the ProgreeBar
mLoadingIndicator.setVisibility(View.INVISIBLE);
super.onFilterComplete(count);
}
}
Pass the reference to the ProgressBar
with the setLoadingIndicator()
method. This assumes that you're making the web service requests in the adapter(of the AutoCompleteTextView
)/the adapter's filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With