Search code examples
androidtextviewformat

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


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


Solution

  • It is possible, refer to this

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