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.