-1

i am kind of starting coding in android studio. I am trying to get my TextView to be displayed in the app like the below example:

1 2 3 4 5 . . .

Like this

Is it possible to change the TextView itself withing the Java xml text Activity or must there be a code written in the mainactivity?

If any of the named above, could you please reach out for me the code for that with a simple and short explanation of what is happening and why is it needed?

Thanks a lot in advance guys!

Have a nice day! Regards

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
himalczyk
  • 13
  • 3

2 Answers2

0

If you include in the text \n after every char you get what you want:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n.\n.\n."
forpas
  • 160,666
  • 10
  • 38
  • 76
  • Ok i never thought about using this. Tried several ways but never thought it would be that easy :) Thank you. – himalczyk Nov 25 '18 at 22:16
0

you just need to add new line after every letter, for do it, you need to use simple loop to get letter by Index, and String to cat result, then set result in the TextView after loop complete, this is the java code, just copy past and change textview id to your textview id:

TextView myTextview = findViewById(R.id.textview_id);
String Result = "";
for(int i = 0; i < myTextview.length(); i++){
    Result = Result + "\n" + myTextview.getText().toString().charAt(i);
}
Result = Result.replace(" ", "");
myTextview.setText(Result.trim());
Abdomns
  • 428
  • 3
  • 8