简体   繁体   中英

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". However if the user were to close the app and start it again. The imageview is "gone".

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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