简体   繁体   English

ImageButton 设置为双击后可见,应用重启后变为不可见

[英]ImageButton set to be visible after double click becomes invisible after app restarts

I have an imagebutton in my xml layout file that is initially set to "gone", but once a user performs a double click it becomes "visible".我的 xml 布局文件中有一个图像按钮,最初设置为“消失”,但一旦用户执行双击,它就会变为“可见”。 However if the user were to close the app and start it again.但是,如果用户要关闭应用程序并重新启动它。 The imageview is "gone". imageview“消失了”。

holder.binding.date.setOnClickListener(object : DoubleClickListener(){
        override fun onDoubleClick(v: View) {
            holder.binding.markAsImportant.visibility = View.VISIBLE
            Toast.makeText(context, "Marked as important", Toast.LENGTH_SHORT).show()
        }
    })
}

I would like the imagebutton to still be visible after the app is closed and started again.我希望图像按钮在应用程序关闭并重新启动后仍然可见。

When the app is closed and restarted the xml is loaded again, so the button being gone is expected.当应用程序关闭并重新启动时,xml 将再次加载,因此按钮消失是意料之中的。

If you want to remember something across app runs, then you need to use persistent storage.如果你想在应用程序运行时记住一些东西,那么你需要使用持久存储。 For something this simple, I'd suggest you use SharedPreferences .对于这么简单的事情,我建议您使用SharedPreferences

You can make your image view visible and store a value when the user double clicks.您可以使图像视图可见并在用户双击时存储一个值。 And then when the app is started read that stored value to see if the user double clicked in a previous session and set the visibility of the image view.然后当应用程序启动时,读取该存储值以查看用户是否双击之前的 session 并设置图像视图的可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM