Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tabulator / tabspace in a TextView

Tags:

I wish to use some tabspace in a line where I call setText

if(id==R.id.radioButton1){             title.setText(numbertext.getText()+" Grams"); 

In this case I would like to tab between numbertekst.getText() and the grams. The output is part of a simple row with values. But as I can't find the tab, the row is a little ugly.

I know I can use multiple textfields or even a table. But as I have a lot of code already I don't want to go that way yet.

I tried the Java way with putting \t, however that seems not to work.

Any help would be appreciated.

like image 354
Michel Avatar asked Jan 28 '13 21:01

Michel


People also ask

How do you strikethrough text in TextView?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.

How do I assign text to TextView?

Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method. The text is set via the android:text attribute. You can either set the text as attribute value directly, or reference a text defined in the strings.

Can we change the text in TextView?

TextView tv1 = (TextView)findViewById(R. id. textView1); tv1. setText("Hello"); setContentView(tv1);

How do you create a TextView control in an activity file?

Modify src/MainActivity. java file to add necessary code . Modify the default content of res/layout/activity_main. xml file to include Android UI control.


2 Answers

You should add tabulator to the text, but \t don't work in settext. The solution is add the character \u0009 that represents in unicode char the tabulator, in a string resource.

<string name="tab">\u0009</string>  TextView hello = (TextView) findViewById(R.string.helloTextView);  hello.setText("e"+getString(R.string.tab)+"e"); 

just combine more tab to have more space

getString(R.string.tab)+getString(R.string.tab)+getString(R.string.tab) 
like image 71
StarsSky Avatar answered Sep 19 '22 15:09

StarsSky


"\t" works as well, and "\n" is used to start new line

like image 44
user3574895 Avatar answered Sep 21 '22 15:09

user3574895