【问题标题】:Android ListView's item's Image background color does not changeAndroid ListView item 图片背景颜色不改变
【发布时间】:2017-11-02 16:49:52
【问题描述】:

我有一些 Android 应用程序,它是 JavaKotlin 的混合体,在这个应用程序中我有 Listview,其中包含可用的 WiFi 网络。当我选择这个ListView 的元素时,Dialog 会弹出要求用户干预,到目前为止一切正常。现在,当我按下Submit button 时,这个Dialog 隐藏,并且选定的ListView 的项目ImageView 应该得到Steelblue 颜色,但它没有:

    dialog.buttonNewGroup.setOnClickListener { _: View? ->
        val newGroupDialog: MaterialDialog = MaterialDialog.Builder(this@AddDevicesActivity)
                .title(R.string.new_group_dialog_title)
                .content(R.string.new_group_dialog_content)
                .inputType(InputType.TYPE_CLASS_TEXT
                        + InputType.TYPE_TEXT_VARIATION_NORMAL
                        + InputType.TYPE_TEXT_FLAG_AUTO_CORRECT + InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE + InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
                .inputRange(1, 32)
                .input(R.string.group_name, 0, false, { _, _ -> })
                .negativeText(R.string.cancel)
                .positiveText(R.string.submit)
                .onPositive { dialog, _ ->
                    // Add new group to database
                    mDb.addGroup(VentGroup(dialog.inputEditText?.text.toString()))
                    // Get refreshed list of the groups
                    mGroups.clear()
                    mDb.getGroups().toCollection(mGroups)
                    mGroupsAdapter.notifyDataSetChanged()
                    this@AddDevicesActivity.imageView.setBackgroundColor(Color.parseColor("0xff4682b4"))    // IMAGE BACKGROUND DOES NOT CHANGE TO "Steelblue" color
                }
                .build()
        newGroupDialog.show()
    }

我在这部分代码中添加了断点,它确实得到了执行,但是,ImageViewbackground 没有改变。为什么?

P.S.:我是 Kotlin 的新手,而 Android/Java 的新手,我要求在投反对票之前稍微了解一下,因为我知道这背后一定有一些愚蠢的错误。

【问题讨论】:

    标签: java android listview kotlin


    【解决方案1】:

    你好 KernelPanic 试试,

    (dialog.actiivty as AddDevicesActivity).imageView.setBackgroundColor(Color.parseColor("0xff4682br"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2018-11-18
      • 1970-01-01
      相关资源
      最近更新 更多