首页 > 解决方案 > 点击文本并在 android studio 中显示弹出消息

问题描述

我的应用中有一些文本是我在 android studio 中使用 kotlin 创建的。对于这个应用程序,我想保留一条弹出消息,以便我点击文本,一个小的弹出窗口会在该弹出窗口中向我显示相同的文本。我正在使用回收站视图。UI 的快照如下所示。

用户界面

因此,我应该能够点击文本并获得包含相同文本的弹出消息。由于我是 android studio 的业余爱好者,因此我需要一些帮助。我一直在搜索并找到类似的解决方案DialogAlertDialog但我不知道在这种情况下应该如何使用它们。顺便说一句,这里没有按钮,它是一个简单的 textView。

任何帮助表示赞赏。

标签: androidandroid-layoutandroid-studioandroid-recyclerviewkotlin

解决方案


我找到了一种使用AlertDialog. 下面给出了对我有用的代码片段。

val mAlertDialogTextView = holder?.view?.textView_subtopic_title //textView_subtopic_title is the view of my choice which needs to popup a message.
            mAlertDialogTextView?.setOnClickListener {
                val mAlertDialog = AlertDialog.Builder(context)
                mAlertDialog.setMessage(key.toString())
                mAlertDialog.setNegativeButton("cancel",{ dialogInterface: DialogInterface, i: Int -> dialogInterface.dismiss()})
                mAlertDialog.show()
            }

谢谢大家的支持。


推荐阅读