Search code examples
androidstringandroid-edittextsettext

How do i start a new line in String?


Possible Duplicate:
how do i create a multiline string in EditText?

i want to display a string in a multiline EditText. Currently, the string displays as....

Receive: 0 coin(s) Total
             Cost: $100

I want want it to display as...

Receive: 0 coin(s) 
Total Cost: $10

This is my code, I have tried to use "\n", but to no avail...

result.setText("Receive:"+ " "+ df.format(rawounces)+"coin(s)" + "\n" 
     + "Total Cost:$" + df.format(transactionandpremium*rawounces));

Thank you in advance.


Solution

  • You can use the Html attribute to set text as you want as ::

    <EditText
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       />
    
    String str="Receive: 0 coin(s) <br> Total Cost: $10";
    editText.setText(Html.formHtml(str));