Android Programming Tutorials

(Romina) #1
Getting More Active

public class LunchList extends ListActivity {
public final static String ID_EXTRA="apt.tutorial._ID";
Cursor model=null;
RestaurantAdapter adapter=null;
EditText name=null;
EditText address=null;
EditText notes=null;
RadioGroup types=null;
RestaurantHelper helper=null;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


helper=new RestaurantHelper(this);


name=(EditText)findViewById(R.id.name);
address=(EditText)findViewById(R.id.addr);
notes=(EditText)findViewById(R.id.notes);
types=(RadioGroup)findViewById(R.id.types);


model=helper.getAll();
startManagingCursor(model);
adapter=new RestaurantAdapter(model);
setListAdapter(adapter);
}


@Override
public void onDestroy() {
super.onDestroy();


helper.close();
}


@Override
public void onListItemClick(ListView list, View view,
int position, long id) {
Intent i=new Intent(LunchList.this, DetailForm.class);


i.putExtra(ID_EXTRA, String.valueOf(id));
startActivity(i);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.option, menu);


return(super.onCreateOptionsMenu(menu));
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {


127
Free download pdf