How to get EditText value and display it on screen through TextView?
AndroidAndroid LayoutTextviewAndroid Problem Overview
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, want to know what modifications can be done on the string.xml file to do this.
Android Solutions
Solution 1 - Android
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..
Solution 2 - Android
I'm just beginner to help you for getting edittext value to textview. Try out this code -
EditText edit = (EditText)findViewById(R.id.editext1);
TextView tview = (TextView)findViewById(R.id.textview1);
String result = edit.getText().toString();
tview.setText(result);
This will get the text which is in EditText
Hope this helps you.
Solution 3 - Android
EditText ein=(EditText)findViewById(R.id.edittext1);
TextView t=new TextView(this);
t.setText("Your Text is="+ein.getText());
setContentView(t);
Solution 4 - Android
bb.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
String s1=tt.getText().toString();
tv.setText(s1);
}
}
);
Solution 5 - Android
First get the text from edit text view
edittext.getText().toString()
and Store the obtained text in a string, say value
.
value = edittext.getText().toString()
Then set value
as the text for textview
.
textview.setText(value)
Solution 6 - Android
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);
}
});
Solution 7 - Android
Easiest way to get text from the user:
EditText Variable1 = findViewById(R.id.enter_name);
String Variable2 = Variable1.getText().toString();
Solution 8 - Android
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
Solution 9 - Android
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.
Solution 10 - Android
Try this->
EditText text = (EditText) findViewById(R.id.text_input);
Editable name = text.getText();
Editable is the return data type of getText() method it will handle both string and integer values
Solution 11 - Android
First get the value from edit text in a String variable
String value = edttxt.getText().toString();
Then set that value to textView
txtview.setText(value);
Where edttxt refers to edit text field in XML file and txtview refers to textfield in XML file to show the value