Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add value (setText) to a material design TextInputLayout?

How do i setText to a material design TextInputLayout (Material Design) in android studio?

 //setValue
   BarCode.setText(MainPage.ResultCode.getText());
    TextInputLayout BarCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_discharge_product);

        BarCode = findViewById(R.id.barcodeAdd);
        BarCode.setText(MainPage.ResultCode.getText()

The above code did not work for me.

My xml code:

<com.google.android.material.textfield.TextInputLayout
     android:id="@+id/barcodeAdd"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"   

     style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

      <com.google.android.material.textfield.TextInputEditText
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:hint="Bar Code"/>

</com.google.android.material.textfield.TextInputLayout>
like image 612
Anesu Phiri Avatar asked May 04 '20 13:05

Anesu Phiri


1 Answers

this is the syntax.. use it as appropriate in you code:

mTextInputLayout.getEditText().setText("ur text");

and

mTextInputLayout.getEditText().getText()
like image 169
Vikram Baliga Avatar answered Sep 28 '22 03:09

Vikram Baliga