问题
I have a table with different columns. instead of creating text view for each item i want to have one textview for each row. i want to add each item one by one to row string. because some items 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 do same way with textview? if yes how to do that. Thanks
回答1:
It is possible, refer to this
String text = String.format("%0d", n);
textView.setText(text);
回答2:
http://developer.android.com/guide/topics/resources/string-resource.html
Formatting strings
<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);
来源:https://stackoverflow.com/questions/10877742/android-is-it-possible-to-format-textview-like-system-out-format02d-n