Loading indicator on the right in AutoCompleteTextView

I populate my AutoCompleteTextView with data received from the web server. It takes 3-5 seconds. If it is not indicated that no one is waiting for its autocomplete. Therefore, I want to show such an indicator:

enter image description here

I tried this:

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> 

But that did not work. Proper extension is stationary.

Also the above view of the image of the layout having the ImageView , AutoCompleteTextView , ProgressBar and go Button search all on the background without borders ? So, the ProgressBar looks like inside an AutoCompleteTextView .

Thanks.

+6
source share
1 answer

You want to use progress bars other than spinners. Use a graphical view to position them on top of the AutoCompleteTextView fields and set their identifier. I set my course to progress.

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

Then in your activity / fragment:

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

It is automatically displayed, so we originally hid it. Then we set it to VISIBLE on your addTextChangedListener in AutoCompleteTextView. Then, when these tasks are completed, you return them back to hidden.

0
source

Source: https://habr.com/ru/post/949965/


All Articles