How to get EditText value and display it on screen through TextView?

前端 未结 11 1953
南旧
南旧 2020-12-05 12:45

I want to get the user input for the EditText view and display it on the screen through TextView when the Button is clicked. I also, w

相关标签:
11条回答
  • 2020-12-05 13:15
    yesButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            eiteText=(EditText)findViewById(R.id.nameET);
            String result=eiteText.getText().toString();
            Log.d("TAG",result);
        }
    });
    
    0 讨论(0)
  • 2020-12-05 13:26

    I didn't get the second question, maybe you can elaborate...but for your first query.

    String content = edtEditText.getText().toString(); //gets you the contents of edit text
    tvTextView.setText(content); //displays it in a textview..
    
    0 讨论(0)
  • 2020-12-05 13:28

    Use the following code when clicked on the button :

     String value = edittext.getText().toString().trim(); //get text from editText 
     textView.setText(value); //setText in a textview
    

    Hope to be useful to you.

    0 讨论(0)
  • 2020-12-05 13:30

    Easiest way to get text from the user:

    EditText Variable1 = findViewById(R.id.enter_name);
    String Variable2 = Variable1.getText().toString();
    
    0 讨论(0)
  • in "String.xml" you can notice any String or value you want to use, here are two examples:

    <string name="app_name">My Calculator App
        </string>
    <color name="color_menu_home">#ffcccccc</color>
    

    Used for the layout.xml: android:text="@string/app_name"

    The advantage: you can use them as often you want, you only need to link them in your Layout-xml, and you can change the String-Content easily in the strings.xml, without searching in your source-code for the right position. Important for changing language, you only need to replace the strings.xml - file

    0 讨论(0)
提交回复
热议问题