-
Android Lurker
Want to Learn Hello World Tutorial in More Detail
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?
-
09-22-2011 08:32 PM
# ADS
Google Advertisement
-
Android Lurker
Do you have any experience in Java? if not then the following wouldnt make any sense.
I'm a noob to Android myself so I dont know if its entirely correct
TextView is a class in widget that is used to well, see text, and "tv" is an instantiation of TextView with parameter "this."
the setText() is a method I assume in TextView which takes a String parameter, and setContentView() is another method that is which is used to show what ever TextView objects you made, which is why "tv" is a parameter in the setContentView method.
From what i deduce the code to type "Good bye android" alongside each other, you would create a second file printing "Goodbye android" have to use the "Intent" and the code format is likethis:
Intent intent = new Intent ("name of the file youre coming from", "name of the file youre gonna end up in")
startActivity(intent)
for example:
Intent intent = new Intent(File A, File B);
startActivity(intent);
but you also have to change one stuff in the XML files as well (if there is any)
Hoped this helped
-
App Developer
add a newline character "\n"
-
Android Lurker
i think you can find all details of 'hello World' example on Android developers site.
You can define your string in stings.xml that is located in res-->values in package explorer.
You can create a resource element object that contain your string 'Good bye Android' with any name( such as 'myStr'). then you can use the following
v.setText("@strings/myStr);
But you can find another simple example with better explanation on here first Android project
Thanks
If you any problem the let me know