1

I cannot make Button invisible and TextView visible after clicking on the Button. Here is XML code

 `<androidx.constraintlayout.widget.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".AttentionActivity">

 <Button
    android:id="@+id/buttonIagree"
    android:text="I AGREE" />

 <TextView
    android:id="@+id/wait"
    android:text="@string/wait"
    android:visibility="invisible" />`

and Java code

   `Button button = findViewById(R.id.buttonIagree);
    TextView wait = findViewById(R.id.wait);


    button.setOnClickListener(v -> {

        wait.setVisibility(View.VISIBLE);
        button.setVisibility(View.GONE);

        if (wait.getVisibility() == View.VISIBLE && button.getVisibility() == View.GONE) {
            t.start();`

t starts without any problems and works fine, but the Button stays visible and TextView stays invisible. I've tried to put button and textview in global variables and in LinearLayout with the same result. What am I doing wrong?

kvocha
  • 21
  • 5
  • Try adding constraints to TextView and Button. Also, set color of TextView to something that jumps out from background to test. Why didn't you set width & height of elements? – isaaaaame Apr 14 '23 at 06:34
  • @kvocha Have you shortened xml file? – Abdullah Javed Apr 14 '23 at 06:56
  • I've shortened xml file here. Constrains width and height are on their places. Now Activity is in LinearLayout but it doesn't help. – kvocha Apr 14 '23 at 07:10

1 Answers1

1

The problem was in t. It worked before other processes and closed the app before I could see textView and Button change visibility. Construction if(getVisibility()) didn't work. So I used handler.postDelayed method for t like in this answer.

kvocha
  • 21
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '23 at 07:35