Android Programming Tutorials

(Romina) #1
A Simple Form

package apt.tutorial;

public class Restaurant {
private String name="";
private String address="";

public String getName() {
return(name);
}

public void setName(String name) {
this.name=name;
}

public String getAddress() {
return(address);
}

public void setAddress(String address) {
this.address=address;
}
}

This is simply a rudimentary model, with private data members for the


name and address, and getters and setters for each of those.


Of course, don't forget to save your changes!


Step #6: Save the Form to the Model..................................................


Finally, we want to hook up the Save button, such that when it is pressed,


we update a restaurant object based on the two EditText fields. To do this,


open up the LunchList/src/apt/tutorial/LunchList.java file and replace the


generated Activity implementation with the one shown below:


package apt.tutorial;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LunchList extends Activity {
Restaurant r=new Restaurant();

@Override

15
Free download pdf