How to edit a TextView like below?

48 Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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."
0
On

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());