Android Is it possible to format a text image, for example, System.out.format ("% 02d", n);?

I have a table with different columns. instead of creating a text view for each item, I want to have one text view for each line. I want to add each element one at a time to a row string. because some elements may have 1 digit and some others may have two digits, I want to format it.

in Java we do something like:

intn = 7;
System.out.format("%0d", n);      //  -->  "07"

Is it possible to do the same with textview? if so, how to do it. Thanks

+1
source share
2 answers

Perhaps refer to this

String text = String.format("%0d", n);
textView.setText(text);
+3
source

http://developer.android.com/guide/topics/resources/string-resource.html

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
+8

Source: https://habr.com/ru/post/1653759/


All Articles