In this post, I'll give you the code for creating a simple Welcome Application using widgets. After you create a project ( File - New -Project-Android Project), lets say Welcome, you'll get a file called Welcome.java. Replace the following code with the existing code:
package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
import android.content.Intent;
public class Hello extends Activity {
/** Called when the activity is first created. */
TextView a,b,c;
Button d;
EditText e;
String sname;
@Override
public void onCreate(Bundle savedInstanceState) {
a=(TextView)findViewById(R.id.Name);
b=(TextView)findViewById(R.id.wel);
c=(TextView)findViewById(R.id.msg);
d=(Button)findViewById(R.id.sub);
e=(EditText)findViewById(R.id.nm);
e.setText(" ");
d.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sname=e.getText().toString();
c.setText(sname);
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Main.xml
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>