Kev88 Kev88 - 2 months ago 8
Java Question

I need to pass a string into textview in android

I want to pass a string into textview in android, (I have made an attempt below) I just want it to take in text from text view assign it to a string the output the string in textview. any help would be great!!

String str;
EditText e1 = (EditText)findViewById(R.id.input); //take text assign to e1
str = e1.getText().toString() //take text from e1 and assign it to string str
TextView str= (TextView)findViewById(R.id.output);//

Answer

Try the following code:

// Take text assign to e1 
EditText e1 = (EditText) findViewById(R.id.input);

// Take text from e1 and assign it to string str
str = e1.getText().toString();

// Take text from e1 and assign it to string str
String str = e1.getText().toString();

TextView out= (TextView)findViewById(R.id.output);
out.setText(str);
Comments