setVisibilty, чтобы видеть из ушедшего не обновляется в режиме реального времени - PullRequest
0 голосов
/ 27 октября 2018

Я пытаюсь просто изменить видимость макета с «ушел» на «видимый».процесс довольно прост, нажатие на 'fab' изменит видимость определенного макета (в данном случае: 'threeVal_layout') с исчезнувшего на видимый.По какой-то причине код работает при запуске без отладки (что означает, что макет действительно меняется на видимый), но после использования режима отладки макет не обновляется после выполнения кода, только после того, как я вернусь на экран и нажму наПотрясающе еще раз.

Я вижу ошибку, прикрепленную к изображению внутри View.class, как только я вхожу в функцию 'setVisiblty'.

мой код:

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

...