How to add loading indicator in AutoCompleteTextView

I want to show the loading indicator in AutoCompleteTextView when loading data from a web service. Preferably, this should be shown on the right side of autofill (fi animation, as in progress control - a spinning wheel). How can I do that?

+6
source share
3 answers

I want to show the loading indicator in AutoCompleteTextView while loading data from a web service.

Place an indefinite ProgressBar to the right of the widget and extend the AutoCompleTextView class as follows:

 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 about to show // the drop down so close/hide the ProgreeBar mLoadingIndicator.setVisibility(View.INVISIBLE); super.onFilterComplete(count); } } 

Pass the link to the ProgressBar using the setLoadingIndicator() method. It is assumed that you are making web service requests in the adapter (from AutoCompleteTextView ) / adapter filter.

+5
source

You want to use progress bars other than spinners. Use a graphical view to position them on top of the AutoCompleteTextView fields and set their identifier. I set my course to progress.

 <ProgressBar android:id="@+id/progressLoading" style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/autoCompleteTextViewId" android:layout_alignTop="@+id/autoCompleteTextViewId" android:paddingTop="14dip" android:paddingRight="10dip" /> 

Then in your activity / fragment:

 final ProgressBar barProgress = (ProgressBar) findViewById(R.id.progressLoading); originProgress.setVisibility(View.GONE); 

It is automatically displayed, so we originally hid it. Then we set it to VISIBLE on your addTextChangedListener in AutoCompleteTextView. Then, when these tasks are completed, you return them back to hidden.

+1
source

To add a progress bar to AutoCompleteView, you can easily do the following:

First create your own autocomplete class, for example:

 public class AutoCompleteWithLoading extends AutoCompleteTextView{ private ProgressBar mLoadingIndicator; public AutoCompleteWithLoading(Context context) { super(context); } public AutoCompleteWithLoading(Context context, AttributeSet attrs) { super(context, attrs); } public AutoCompleteWithLoading(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public AutoCompleteWithLoading(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @TargetApi(Build.VERSION_CODES.N) public AutoCompleteWithLoading(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, Resources.Theme popupTheme) { super(context, attrs, defStyleAttr, defStyleRes, popupTheme); } public void setLoadingIndicator(ProgressBar progressBar) { mLoadingIndicator = progressBar; } public void dispayIndicator(){ if(mLoadingIndicator != null){ mLoadingIndicator.setVisibility(View.VISIBLE); } this.setText(""); } public void removeIndicator(){ if(mLoadingIndicator != null){ mLoadingIndicator.setVisibility(View.GONE); } } } 

Then add this to your XML

  <thriviastudios.com.views.view.AutoCompleteWithLoading android:padding="10dp" android:layout_margin="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/NotPresentationText" android:id="@+id/activity_activities_search_city_text_view" android:popupBackground="@color/app_bg" android:layout_centerInParent="true" android:background="@color/app_bg_darker" android:singleLine="true" android:hint="City" android:imeOptions="actionDone" android:textColorHint="@color/white" /> <ProgressBar android:id="@+id/loading_indicator" style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:layout_marginRight="20dp" android:visibility="gone"/> </FrameLayout> 

NB: use the full path to the Custom AutomComplete class

Then, in your activity or fragment, you will receive a link to the indicator, as well as to autocomplete. Attach the progress bar to autocomplete as follows:

 city.setLoadingIndicator(indicator); 

and you can additionally show or remove the indicator if desired as follows:

 city.dispayIndicator(); 

and

 city.removeIndicator(); 

I hope this helps someone.

0
source

All Articles