Last time I posted, it was with the iphone tutorial on how to make a iPhone app that changes a text field to a value once a button is pressed.
Well I am here once more, but this time it is with Android!
Now if you have not got it already, go and get the Android sdk from developer.android.com.
It has guides on how to install it on the 3 major OSs, also follow how to make a AVD (Android Virtual Device) as I will not be covering that in this tutorial.
Once all that has been done, launch your IDE (in 99% of cases it will be eclipse with the android plugin). And make a new project.
Fill out the data similiar to the picture

Once that is done you should see your new project in the project explorer. Find main.java ( or what ever you called your activity, it will be in the same location )

Once you find it, double click it and it will load the main activity file into the eclipse editor. Now to make those important changes ( If you followed my iPhone tutorial you will notice there is not as much commented code here. Google expect you right your own methods). As previously, all bolded text is text added.
package com.mybuttonisawesome;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class main extends Activity {
Button myButton;
TextView myLabel;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button)findViewById(R.id.Button01);
myLabel = (TextView)findViewById(R.id.TextView01);
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myLabel.setText("Moo");
}
});
}
}
If you notice a red underline under TextView or Button, hover your mouse over them and eclipse will suggest importing the needed file.

Now to go to the ui editor, find main.xml in the folder Layouts, under Res in the project explorer.

You should now see a black rectangle with “Hello world!” therein, now you have to delete this. Click on it and press delete on your keyboard, or right click then click remove.
Add a TextView and a Button to the black box from the side panel (under views) and thats it. You do not need to bind them like the iPhone.

Launch your AVD and click Run then Run from the toolbar, (cmd + shift +f11 for mac). It should load after a while and when you click the button the textview text will change
Hope this help



