0

I'm trying a simple act of changing a layout visibility from 'gone' to 'visible'. the flow is quite simple, clicking on a 'fab' will change the visibilty of a specific layout (in this case: 'threeVal_layout') from gone to visible. For some reason, the code is working when running without debugging(which means the layout does change to visible), but once I use debug mode the layout is not updated after the code is executed, only after I return to the screen and click on the fab one more time.

I do see the error attached in the image inside View.class, once I step in the 'setVisiblty' function.

my code:

public class SubmitStringsActivity extends AppCompatActivity{
RandomFunctions randomFunc = new RandomFunctions();
EditText firstVal,secVal,thirdVal;
TextInputLayout firstVal_layout,secVal_layout;
public static TextInputLayout threeVal_layout;
FloatingActionButton btn_go,btn_add;
Integer minValOpt= 0;
String firstChoErr,secChoErr,strResult;
public static String[] choicesArr = new String[2];    //Initialize array for 2 since minimum options is 2

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send_strings);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    /*First Value*/
    firstVal = findViewById(R.id.firstVal);
    firstVal_layout = findViewById(R.id.firstVal_layout);
    /*Second Value*/
    secVal = findViewById(R.id.secVal);
    secVal_layout = findViewById(R.id.secVal_layout);
    /*Third Value*/
    thirdVal = findViewById(R.id.thirdVal);
    threeVal_layout = findViewById(R.id.threeVal_layout);

    btn_add = findViewById(R.id.fab_add);
    btn_add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            threeVal_layout.setVisibility(View.VISIBLE);
            threeVal_layout.invalidate();
            RandomFunctions.addChoiceOption();
        }
    });         btn_go = findViewById(R.id.button);
    btn_go.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), DisplayResultActivity.class);
            // Clean any errors
            firstVal.setError(null);
            // minVal_layout.setErrorEnabled(false);
            secVal_layout.setError(null);
            // maxVal_layout.setErrorEnabled(false);
            //       _End_
            if (firstVal.getText().toString().equals("")) {
                firstChoErr= getString(R.string.emptyChoiceStr);   /**Get the error string from the res*/
                firstVal_layout.setError(firstChoErr);    /**Set error in case minimum value is empty*/
                return;
            }
             else if (secVal.getText().toString().equals("")){
                secChoErr= getString(R.string.emptyChoiceStr);
                secVal_layout.setError(secChoErr);    /**Set error in case maximum value is empty*/
                return;
            }

            else  {
                /** Called when the user taps the Go button */

                    choicesArr[0] = (firstVal.getText().toString());
                    choicesArr[1] = (secVal.getText().toString());
                    int resVal = randomFunc.calculateNums(minValOpt, choicesArr.length-1); //Send minimum and maximum values to random function
                    strResult = choicesArr[resVal];
                    intent.putExtra("intValName", strResult);
                    startActivity(intent);
                    //finish();
                    }
        }
    }

    );
}

}

XML:

<LinearLayout
    android:id="@+id/linearStringLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="56dp"
    android:background="@color/mainBackGroundHalf1"
    android:gravity="center"
    android:orientation="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/firstVal_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:gravity="center"
        app:layout_constraintEnd_toEndOf="@+id/linearStringLayout"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/linearStringLayout">

        <EditText
            android:id="@+id/firstVal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="8dp"
            android:backgroundTint="@color/inputText"
            android:ems="10"
            android:hint="@string/firstString"
            android:imeOptions="actionDone"
            android:inputType="text"
            android:maxLength="9"
            android:selectAllOnFocus="false"
            android:singleLine="true"
            android:textAlignment="center"
            android:textAppearance="@android:style/TextAppearance.Material"
            android:textColorHint="@color/inputText"
            app:layout_constraintBottom_toBottomOf="@+id/linearStringLayout"
            app:layout_constraintHorizontal_bias="0.502"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/secVal_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:gravity="center"
        app:layout_constraintEnd_toEndOf="@+id/linearStringLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/firstVal_layout">

        <EditText
            android:id="@+id/secVal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:backgroundTint="@color/inputText"
            android:ems="10"
            android:hint="@string/secondString"
            android:inputType="text"
            android:maxLength="9"
            android:selectAllOnFocus="false"
            android:singleLine="true"
            android:textAlignment="center"
            android:textAppearance="@android:style/TextAppearance.Material"
            android:textColorHint="@color/inputText" />
    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/threeVal_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:gravity="center"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="@+id/linearStringLayout"
        app:layout_constraintEnd_toEndOf="@+id/linearStringLayout"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/secVal_layout">

        <EditText
            android:id="@+id/thirdVal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="8dp"
            android:backgroundTint="@color/inputText"
            android:ems="10"
            android:hint="@string/threeString"
            android:imeOptions="actionDone"
            android:inputType="text"
            android:maxLength="9"
            android:selectAllOnFocus="false"
            android:singleLine="true"
            android:textAlignment="center"
            android:textAppearance="@android:style/TextAppearance.Material"
            android:textColorHint="@color/inputText"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="@+id/linearLayout"
            app:layout_constraintHorizontal_bias="0.502"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent" />

    </android.support.design.widget.TextInputLayout>
</LinearLayout>

the error I see once in debug mode

dor-b
  • 75
  • 1
  • 9
  • Have you tried doing a Clean Project and debugging your app again? – spuente Oct 27 '18 at 21:07
  • 1
    Check this https://stackoverflow.com/questions/39990752/source-code-does-not-match-the-bytecode-when-debugging-on-a-device – forpas Oct 27 '18 at 21:13
  • I've changed my emulator API level to match the compileSdkVersion, restarted android studio and it worked. – dor-b Oct 29 '18 at 05:36

0 Answers0