开发者

Android eclipse development TextView Assistance

Whats up? I've been trying to learn a few basics when it comes to coding, and I've got a question regarding the helloworld-app.

开发者_开发技巧

A basic Hello world!-app shouldn't be hard to accomplish, as it shows the text "Hello world or whatever..u want it to be". Anyway, how would I go about making it display two, or even three separate lines?

For example:

Hello, world
[Second line]
[Third line]

I just can't figure out how to do this, so if anyone could point me in the right direction, I'd greatly appreciate it!


Isn't \n the way to go on that one?

An other way would be to wrap the TextViews in an LinearLayout, and fill them each with one sentence.

Edit (response to OP):

You can do it programmatically by using the following code (in your onCreate()-

//Grab the TextView that's been deflated from the XML-file
TextView theTextView = (TextView) findViewById(R.id.{The id of your TextView});

//Set the text to a three-rowed message
theTextView.setText("Hello world!\nMy name is ninetwozero.\nLorem ipsum wouldn't fit here");

Remember to change {The id of your TextView} into the actual id of your TextView that's been set in the xml-layout file.


Is this you want??

 <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical">
    <TextView android:text="First Line" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView android:text="Second Line" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView android:text="Third Line" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>


'\n' is a special char that means 'new line' so it is "hello world\nLine 2\nLine 3"


TextView yourText = (TextView)findViewById(TheId);
yourText.setText("Hello \n World \n Welcome to my app ?");

It display something like this : 1st line : Hello. 2nd line : World. 3rd line : Welcom to my app ?

Is it what you wanted ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜