Android Spinner不响应点击,不会关闭,并且不会触发OnItemSelectedListener [英] Android Spinner not responding to clicks, does not close and OnItemSelectedListener does not fire off

查看:757
本文介绍了Android Spinner不响应点击,不会关闭,并且不会触发OnItemSelectedListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Kotlin中开发一个应用程序(如果您不了解Kotlin,我相信您仍然可以在Android/Java体验方面提供帮助)

I am developing an app in Kotlin (if you don't know about kotlin I am sure you can still help with your Android/Java experience)

详细信息:

我的应用程序中有一个微调器,虽然弹出后甚至没有显示一些奇怪的视图,但它对点击都没有响应.因此,也不会触发OnItemSelected侦听器.

I have a Spinner in there my app.Though it is not responding to clicks once it pops up and even shows some weird views. And because of that the OnItemSelected listener is never fired either.

我开始通过AsyncRealm调用更新微调器的方法.

I start the method to update the spinner from an AsyncRealm call.

以下是代码:

整个函数运行,微调器不为null,在附加侦听器之后,它也不再为null(调试时).

This whole function runs, the spinner is not null, after attaching the listener, it is no longer null either (when debugging).

    private fun updateCategorySpinner(result: MutableList<Category>) {
        info("updateCategorySpinner")
        val arrayAdapter: ArrayAdapter<String> = ArrayAdapter(ctx, R.layout.spinner_item, result.map{ it.category })
        arrayAdapter.setDropDownViewResource(R.layout.spinner_item)
        arrayAdapter.notifyDataSetChanged()
        categorySpinner.adapter = arrayAdapter
        info("updateCategorySpinner done")
    }

result.map {..}创建一个带有类别名称的MutableList.

问题:

我不知道为什么会有那些箭头,但是无论我使用哪种布局 使用它们(即使只是一个简单的TextView)

I have no idea why there are those arrows, but no matter what layout I use (even if just a simple TextView) they are there

我在这里想念什么?

禁用侦听器无济于事.

使用Anko附加侦听器无济于事.

Attaching the listener with Anko doesn't help.

监听器在初始化时触发一次,仅此而已.

The listener fires once when it is initialized, that's it.

下拉列表打开后,它就会完全卡住.

Once the dropdown opens it is completely stuck.

我正在用Anko创建视图.

I am creating my views with Anko.

R.layout.spinner-item只是一个<Textview>.

class AddTodoFragmentUi:AnkoComponent<ViewGroup>,AnkoLogger {
    override fun createView(ui: AnkoContext<ViewGroup>): View {
        val editTextTheme = R.style.Widget_AppCompat_EditText

        return with(ui){
            verticalLayout {
                info("inVerticalLayout")
                verticalPadding =dip(15)
                gravity = Gravity.CENTER
                editText(editTextTheme){
                    id = R.id.txt_todo_desc
                    hintResource = R.string.txt_todo_desc_hint
                    width = matchParent

                }
                spinner(R.style.Widget_AppCompat_Spinner){
                    id= R.id.spinner_todo_category
                    prompt = "Select a Category"
                }
                button{
                    id = R.id.btn_add_todo
                    textResource = R.string.btn_add_todo
                    width = matchParent

                }
                button{
                    id = R.id.btn_del_todo
                    textResource = R.string.btn_del_todo
                    width = matchParent
                    visibility = View.INVISIBLE

                }

            }.applyRecursively {view -> when(view){
                is EditText -> view.textSize = 20f
                is Button -> view.textSize = 30f
            }
            }
        }
    }

图片:

推荐答案

好的,因此,非响应性问题在于设置Widget_app_compact微调器主题.

Okay, so the issue of non-responsiveness was with setting up the Widget_app_compact spinner theme.

 spinner(R.style.Widget_AppCompat_Spinner){
                    id= R.id.spinner_todo_category
                    prompt = "Select a Category"

删除它可以解决问题.

请不要像我那样输掉两天,:D.

Don't lose two days as I did on this, please :D.

这篇关于Android Spinner不响应点击,不会关闭,并且不会触发OnItemSelectedListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆