6

我使用从 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);
}
}

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>

但这没有用。右边的drawable是静止的。

上面的图像也是一种在无边界背景中具有搜索ImageView、、AutoCompleteTextViewProgressBargo的布局吗?所以,看起来就像它在里面。ButtonprogressbarAutoCompleteTextView

谢谢你。

4

1 回答 1

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" />

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

final ProgressBar barProgress = (ProgressBar) findViewById(R.id.progressLoading);
originProgress.setVisibility(View.GONE);

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

于 2013-10-20T23:45:48.273 回答