我想在从Web服务加载数据时在AutoCompleteTextView中显示加载指示器。最好将其显示在自动完成功能的右侧(像进度控制之类的动画-纺车)。如何做到这一点?

最佳答案



在小部件的右侧放置一个外观不确定的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);
    }

}

使用ProgressBar方法将引用传递给setLoadingIndicator()。这假定您正在适配器(AutoCompleteTextView的)/适配器的过滤器中发出Web服务请求。

关于android - 如何将加载指示器添加到AutoCompleteTextView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15405363/

10-13 04:35