Android, Is it possible to format textview like System.out.format(“%02d”, n);?

谁都会走 提交于 2019-12-24 08:13:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!