我想在从网络服务加载数据时在 AutoCompleteTextView 中显示加载指示器。最好它应该显示在自动完成的右侧(f.i. 动画,如正在进行的控制 - 纺车)。如何做到这一点?
最佳答案
I would like to show loading indicator in AutoCompleteTextView while loading data from web-service.
在小部件的右侧放置一个具有不确定外观的 ProgressBar
并像这样扩展 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 服务请求。
关于android - 如何将加载指示器添加到 AutoCompleteTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15405363/