如何将加载指示符添加到AutoCompleteTextView

jet*_*hro 6 android autocompletetextview

我想在从Web服务加载数据时在AutoCompleteTextView中显示加载指示器.最好它应显示在自动完成的右侧(fi动画,如进度控制 - 旋转轮).怎么做到这一点?

Luk*_*rog 6

我想在从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);
    }

}
Run Code Online (Sandbox Code Playgroud)

通过参考ProgressBarsetLoadingIndicator()方法.这假设您在适配器(AutoCompleteTextView适配器)的过滤器中进行Web服务请求.