Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add loading indicator to AutoCompleteTextView

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?

like image 259
jethro Avatar asked Mar 14 '13 09:03

jethro


People also ask

What is Android Completionhint attribute in AutoCompleteTextView?

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.

How do I set autocomplete text on Android?

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.

How does AutoCompleteTextView work?

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.

How do I create an auto complete text view field in XML?

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.


1 Answers

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.

like image 117
user Avatar answered Sep 21 '22 10:09

user