• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Modifying hello world in order to learn

ketanco

Newbie
I did the famous hello world tutorial

Code:
package com.mysite.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MysitehelloworldActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);
    }
}


and then it printed "Hello Android" with no problems on the virtual device.

Now I want to print "Good Bye Android" also, in addition to, and below "Hello Android". Ho can I do it? I tried adding another line of tv.setText("Good Bye Android"); below the Hello Andorid line but this time it only displays Good bye Android. How can I make both displayed?
 
Katanco, in this case, the easiest thing to do would be to modify your text string to include the newline escape sequence like this:

tv.setText("Hello, Android\nGood Bye Android");
 
You need to call the setContentView() method before performing any operations on its Views (that includes using the findViewById() method).
 
You need to call the setContentView() method before performing any operations on its Views (that includes using the findViewById() method).

This is true only if you are getting an id handler to a view defined in the xml, which ketanco is not doing.

He is doing it right, and if you want to add Good Bye Android, AccelArlene has the right answer.
 
This is true only if you are getting an id handler to a view defined in the xml, which ketanco is not doing.

He is doing it right, and if you want to add Good Bye Android, AccelArlene has the right answer.

Woops, you are correct. I apologize, I didn't read through the code, I just glanced at it.
 
Back
Top Bottom