'After click view not display on screen if I set visibility to VISIBLE - Android

I got a view and in xml it is visible

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

Then I do some manipulation with the data and I make it to invisible

container.visibility = INVISIBLE

But I have reset button that suppose to set the container back to visible after click

resetBtn.setOnClickListener {
        this.runOnUiThread { // tried this from stack overflow answers
            container.visibility = VISIBLE
        container.invalidate()} // tried this from stack overflow answers
    }

But after click I still do not see that container appears. What might be the issue?



Solution 1:[1]

first of all, be sure that resetBtn is referred to exactly your desired XML file. it's better to use view binding instead of kotlin synthetic.

then try one of these lines in your click listener:

container.visibility = View.VISIBLE
or
container.isVisible = true

Solution 2:[2]

Try to put log inside setOnClickLitener to check whether click works or not.If log message does not appear, it means you have problem with button

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mahmoudreza mohammadian
Solution 2 Jakhongir