2013-07-22 36 views
6

我使用從Web服務器獲取的數據填充我的AutoCompleteTextView。需要3-5秒。如果它沒有指出沒有人等待它的自動完成。因此,我想說明這樣一個指標:在AutoCompleteTextView中加載右側的指示器

enter image description here

我嘗試這樣:

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> 

但是這沒」工作。右邊的繪圖是靜止的。

也就是上面的圖片那種具有搜索ImageViewAutoCompleteTextViewProgressBar和去Button都在一個無國界這種背景的佈局呢?所以,progressbar看起來像它的AutoCompleteTextView裏面。

謝謝。

回答

0

你想使用進度條而不是spinners。使用圖形視圖將它們放置在AutoCompleteTextView字段上並設置其ID。我設定了我的進度加載。

<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上可見。然後,無論何時完成任務,都將其設置回隱藏狀態。