-1

I have a EditText, where the user will input something, a String. And then after pressing the bottom, inverting the whole text and showing it to the user, but, I don't know how to place the String(The inverted text) into the TextView. CODE:

final EditText e=(EditText)findViewById(R.id.escribiraqui); //INPUT
        final TextView T=(TextView)findViewById(R.id.traduccion);         //OUTPUT
        Button TRAD=(Button) findViewById(R.id.traducir);//JUST THE BOTTOM

Forget about inverting the text, now I just want to output the same Text(From the EditText to the TextView).

user3726747
  • 27
  • 1
  • 3

3 Answers3

1

Try this

TextView text = (TextView) findViewById(R.id.textview1);
String mText = text.getText();
text.setText(new StringBuffer(text).reverse().toString());

That's it...

0

If you want to invert (revert) the String and add it to a TextView you can make a call like this: myTextView.setText(new StringBuilder(enteredText).reverse().toString());

Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
0

If you are newbie then first of all do Googling. This is basic Question, Just Search Like Inverting string in android:

There is solution:

return new StringBuffer(s).reverse().toString();

Place in TextView from EditText in one line:

textView.setText(new StringBuffer(editText.getText().toString()).reverse().toString());
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437