我想在從Web服務加載數據時在AutoCompleteTextView中顯示加載指示器。優選地,它應該顯示在自動完成的右側(f.i.動畫,如正在進行的控制 - 旋轉輪)。如何做到這一點?如何將加載指示器添加到AutoCompleteTextView中
6
A
回答
5
我想在AutoCompleteTextView中顯示加載指示器,而 從網絡服務加載數據。
將一個ProgressBar
對widget的右側不確定的外觀和延長AutoCompleTextView
類是這樣的:
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);
}
}
與setLoadingIndicator()
方法傳遞參考ProgressBar
。這假定您在適配器(的AutoCompleteTextView
)/適配器的過濾器中發出Web服務請求。
1
你想使用進度條而不是spinners。使用圖形視圖將它們放置在AutoCompleteTextView字段上並設置其ID。我設定了我的進度加載。
<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" />
然後在你的活動/片段:
final ProgressBar barProgress = (ProgressBar) findViewById(R.id.progressLoading);
originProgress.setVisibility(View.GONE);
它會自動可見,所以我們最初將它設置爲隱藏。然後,我們將它設置爲在AutoCompleteTextView上的addTextChangedListener上可見。然後,無論何時完成任務,都將其設置回隱藏狀態。
0
要在AutoCompleteView中添加一個進度條,你可以很容易地做到以下幾點:
首先創建一個自定義自動完成類,像這樣:
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);
}
}
}
此後,添加到您的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>
注意:使用自定義自動完成類的完整路徑
然後,在您的活動或片段中,您將獲得對該指標的參考以及自動完成。安裝進度條來自動完成,像這樣:
city.setLoadingIndicator(indicator);
和期望的一樣,所以當你可以進一步顯示或刪除指示:
city.dispayIndicator();
和
city.removeIndicator();
我希望這可以幫助別人。
相關問題
- 1. 如何將活動指示器添加到圖像加載
- 2. 將加載指示器添加到Google地圖infoWindow
- 3. 在AutoCompleteTextView中加載右側的指示器
- 4. 將活動指示器添加到UIAlertView
- 5. 如何將加載指標添加到Android Picasso?
- 6. 如何將顏色指示器(LED外觀)添加到JFrame?
- 7. 如何將着色器添加到從STLLoader加載的THREE.Object3D中
- 8. 加載存儲加載指示器
- 9. 將MS Office通信器狀態指示器添加到JSP中
- 10. 如何在iOS的CollectionView的頁腳中添加加載指示器
- 11. 如何將加載器對話框添加到我的webview?
- 12. 如何將加載器圖像添加到HTML5視頻?
- 13. 如何將預加載器文本添加到jQuery Cycle 2
- 14. 如何將加載微調器添加到WooCommerce結帳頁面
- 15. 如何將着色器添加到從OBJMTLLoader加載的THREE.Object3D
- 16. 如何將css類添加到指令?
- 17. 如何將指標添加到UIImagePickerController
- 18. 將圖像添加到ios中的活動指示器
- 19. Aframe將預加載器添加到圖像加載天空
- 20. 如何將圖像添加到HTML中的指定容器?
- 21. 如何給AutoCompleteTextView添加空間建議
- 22. 如何將加載窗口添加到sencha加載中的圖表中
- 23. 如何將列表添加到phpword中加載的模板中
- 24. 在UCollectionView的底部添加活動/加載指示器
- 25. Cycle.js添加加載指示器後HTTP發送多個請求
- 26. 調用Web服務時添加加載指示器 - 目標c
- 27. 如何將下載計數器添加到下載按鈕?
- 28. 如何將加載指示符或「微調器」添加到劍道角度2網格?
- 29. 將指標添加到Carousel
- 30. 如何將自動加載函數添加到CodeIgniter中?