1

In my form, there are two AutoCompleteTextViews which are populated by custom adapter. But searching takes one or two seconds so I want to show users a Loading animation in an AlertDialog. To achieve this I declared a boolean LiveData variable in search adapter and I am observing it at the activity. My aim is, showing AlertDialog when the observed variable is true and dismissing when the variable is false. So it is very strait forward.

Here is the code snippet for showing dialog

// To simplfy question I am using standart AlertDialog, the same problem occurs here,too
        val builder: AlertDialog.Builder? = AlertDialog.Builder(this, R.style.AlertDialogCustom)
        }
        builder?.setMessage("Results are loading")
                ?.setTitle("Loading")
        val dialog: AlertDialog? = builder?.create()

        SearchAdapter.isFetching.observe(this, Observer<Boolean> { isFetching ->
            isFetching?.let {
                if (it) {
                    dialog?.show()
                } else {
                    dialog?.hide()
                }
            }})

The problem is when dialog?.show() code called AutoCompleteTextView's suggestion list doesn't become visible. If I comment that line everything works perfectly except AlertDialog (because I commented show() command).

I captured two videos, at first one dialog?.show() line was commented and AutoCompleteTextView is working normal

And at the second one dialog?.show() line was not commented and AutoCompleteTextView is not working as expected.

I couldn't figure out what is the problem between AutoCompleteTextView's dropdown and AlertDialog and hoping that you can help me find out.

Extra: AlertDialogCustom style is for just changing TextColor to white to show message on black background which is forced by main theme.

<style name="AlertDialogCustom" parent="Theme.MaterialComponents.Dialog.Alert">
        <item name="android:colorAccent">@color/white</item>
    </style>
bahadir arslan
  • 4,535
  • 7
  • 44
  • 82

0 Answers0