10

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>
Anesu Phiri
  • 159
  • 1
  • 1
  • 8

2 Answers2

19

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

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

and

mTextInputLayout.getEditText().getText()
Vikram Baliga
  • 444
  • 5
  • 9
-1

Example:

TextInputEditText inpedit_txt;

inpedit_txt = (TextInputEditText)findViewById(R.id.id_of_input_edit_text);
inpedit_txt.setText(String.valueOf("you Text"))
GURU Shreyansh
  • 881
  • 1
  • 7
  • 19
  • 2
    answer readability can be improved a lot by formatting, eg. sharing code fragments in code blocks. Here you can find details on how to do that and more: https://stackoverflow.com/editing-help – Péter Veres Jul 18 '21 at 23:27