Android Hello World
Top | Android Hello World Example |
Android Hello World
Android Programs…
main.xml
<?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button android:id="@+id/button1"
android:layout_width="318dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/bclick1" />
</LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
< resources>
<string name="hello">Hello World, HelloWorldActivity!</string>
<string name="app_name">Android HelloWorld</string>
<string name="bclick1">Click Here</string>
< /resources>
HelloWorldActivity.java
package com.javaskool;
import com.javaskool.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Hi I am James Bond!!", Toast.LENGTH_LONG).show();
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
< manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"
package="com.javaskool"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Recent Comments