在AutoCompleteTextView中右侧加载指示器

use*_*779 6 android autocompletetextview

我使用从Web服务器获取的数据填充AutoCompleteTextView.这需要3-5秒.如果没有表明它的自动完成没有人等待.因此,我想显示一个这样的指标:

在此输入图像描述

我试过这个:

private class getAutoCompletes extends AsyncTask<String, Void, String> {

private String response;
@Override
protected String doInBackground(String... params) {
    //get autocomplete data
    return response;
}
@Override
protected void onPostExecute(String result) {

autoComplete.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
ArrayAdapter<String> AutoCompleteAdapter = new ArrayAdapter<String>(
                    MainActivity.this,
                    android.R.layout.simple_dropdown_item_1line, autocompletes);
autoComplete.setAdapter(AutoCompleteAdapter);
autoComplete.showDropDown();
}
@Override
protected void onPreExecute() {
    super.onPreExecute();
    autoComplete.setCompoundDrawablesWithIntrinsicBounds(0, 0,
            R.drawable.rotating_drawable, 0);
}
}
Run Code Online (Sandbox Code Playgroud)

R.drawable.rotating_drawable

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:drawable="@drawable/spinner1"
        android:duration="50"/>
    <item
        android:drawable="@drawable/spinner2"
        android:duration="50"/>
    <item
        android:drawable="@drawable/spinner3"
        android:duration="50"/>
    <item
        android:drawable="@drawable/spinner4"
        android:duration="50"/>

</animation-list>
Run Code Online (Sandbox Code Playgroud)

但这没效果.右侧抽屉是固定的.

同样是上面的图片那种具有搜索布局中ImageView,AutoCompleteTextView,ProgressBar和去Button都在一个无国界这种背景?所以,progressbar看起来就像它里面的那样AutoCompleteTextView.

谢谢.

upi*_*own 0

您想使用进度条而不是旋转器。使用图形视图将它们放置在 AutoCompleteTextView 字段上并设置它们的 id。我将我的设置为progressLoading。

<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" />
Run Code Online (Sandbox Code Playgroud)

然后在您的活动/片段中:

final ProgressBar barProgress = (ProgressBar) findViewById(R.id.progressLoading);
originProgress.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)

它会自动可见,因此我们最初将其设置为隐藏。然后我们在 AutoCompleteTextView 上的 addTextChangedListener 上将其设置为 VISIBLE。然后,每当该任务完成时,您将其设置回隐藏状态。