Home > OS >  how to get text from a TextInputEditText?
how to get text from a TextInputEditText?

Time:05-12

I have this for the TextInputEditText:

<com.google.android.material.textfield.TextInputEditText
    android:id="@ id/textInputEditText"
    android:layout_width="335dp"
    android:layout_height="255dp"
    android:background="@color/white"
    android:hint="@string/tells_us_your_behave"
    android:minWidth="4dp"
    android:minHeight="48dp"
    android:textColor="@color/black"
    android:textColorHint="#757575"
    android:visibility="visible"
    app:layout_constraintBottom_toTopOf="@ id/textView2"
    app:layout_constraintTop_toBottomOf="@ id/textView"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="37dp"
    tools:visibility="visible"
    />

This is for the "Submit" button:

<Button
    android:id="@ id/button5"
    android:layout_width="321dp"
    android:layout_height="75dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="32dp"
    android:text="@string/submit"
    android:textSize="20sp"
    android:onClick="text"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.585"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@ id/ratingBar3"
    tools:ignore="OnClick" />

and I have this for the MainActivity:

public class MainActivity extends AppCompatActivity {
    private TextInputLayout text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        int x = Random();
        if (1 % 2 == 0) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
        else
        {   super.onCreate(savedInstanceState);
            setContentView(R.layout.login_layout);
        }

    }
    public static int Random() {
        Random x = new Random();
        return x.nextInt(100);
    }
    public void userlayout(View view){
        setContentView(R.layout.user_activity_layout);

    }

    public void activityAfterLogIn(View view){
        setContentView(R.layout.activity_main);
        System.out.println(R.id.username);
    }

    public void text(View view) {
        text= findViewById(R.id.textInputEditText);
        setContentView(R.layout.talking);
        System.out.println(text);
        //ai.aici(text.getEditText().getText().toString(), view);
    }

    public void talk(View view){
        setContentView(R.layout.talking);
    }

}

I am trying to get the text from the TextInputEditText and send to a java class, I don t know what is wrong here.

CodePudding user response:

Add this below the findViewById line of code in the text public void method

String getEditText = text.getText.toString();
System.Out.Println(getEditText);

CodePudding user response:

Okay try to log it and see by adding this

Log.d("Edit Text", getEditText);

then input any string and check log

  • Related