How can I add a value (setText) to a Material Design TextInputLayout?
Asked Answered
A

3

12

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>
Alameda answered 4/5, 2020 at 13:34 Comment(7)
You should set text to the TextInputEditText or EditTextBoony
@Nongthonbam Tonthoi, can you please a snippet pleaseAlameda
What is BarCode ? I guess it is the TextInputLayout, so instead of it use the TextInputEditText. Post the relevant part of the code.Boony
@ Nongthonbam Tonthoi, i have edited the code above.Alameda
What is barcodeAdd ? You can see it in the xml fileBoony
barcodeAdd is the id of the TextInputLayout input. i have uploaded the xml fileAlameda
Let us continue this discussion in chat.Boony
T
20

This is the syntax... use it as appropriate in your code:

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

and

mTextInputLayout.getEditText().getText()
Trouper answered 4/5, 2020 at 14:59 Comment(0)
Q
0

I think this works:

binding.istwert.editText?.text = binding.inhalt.editText?.text
Queridas answered 29/9, 2023 at 17:36 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Harder
T
-1

Example:

TextInputEditText inpedit_txt;

inpedit_txt = (TextInputEditText)findViewById(R.id.id_of_input_edit_text);
inpedit_txt.setText(String.valueOf("Your text"))
Tilth answered 18/7, 2021 at 16:36 Comment(1)
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: stackoverflow.com/editing-helpNalley

© 2022 - 2024 — McMap. All rights reserved.