2013-03-14 12 views

Odpowiedz

5

Chciałbym pokazać wskaźnik ładowania w AutoCompleteTextView podczas ładowanie danych z usługi internetowej.

Umieść ProgressBar z nieokreślonym wyglądzie po prawej stronie widgetu i rozszerzyć klasę AutoCompleTextView tak:

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); 
    } 

} 

Przepuścić odniesienie do ProgressBar metodą setLoadingIndicator(). Zakłada się, że tworzysz żądania usługi sieciowej w adapterze (z AutoCompleteTextView)/filtrze adaptera.

1

Chcesz użyć pasków postępu, a nie spinnerów. Użyj widoku graficznego, aby umieścić je na polach AutoCompleteTextView i ustawić ich identyfikator. Postawiłem moje na postęp w śledzeniu.

<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" /> 

Następnie w swojej działalności/fragmentu:

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

To jest automatycznie widoczna więc wstępnie ustawić go w ukryciu. Następnie ustawiliśmy go na VISIBLE na twoim addTextChangedListener w AutoCompleteTextView. Następnie za każdym razem, gdy te zadania się zakończą, powracasz do ukrytego.

0

Aby dodać pasek postępu w ramach AutoCompleteView, można łatwo wykonać następujące czynności:

Najpierw należy utworzyć klasę klienta autouzupełniania tak:

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); 
     } 
    } 
} 

Następnie dodać go do 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: Użyj pełnej ścieżki do niestandardowej klasy AutomComplete

Następnie, w swojej Działalności lub fragmencie, dostajesz odniesienie do wskaźnika, jak również Autouzupełniania. Zamocować pasek postępu do autouzupełniania tak:

city.setLoadingIndicator(indicator); 

i można dodatkowo wyświetlić lub usunąć wskaźnik gdy pożądane tak:

city.dispayIndicator(); 

i

city.removeIndicator(); 

Mam nadzieję, że ktoś pomoże .

Powiązane problemy