Android Programming Tutorials

(Romina) #1
Menus and Messages

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.toast) {
String message="No restaurant selected";


if (current!=null) {
message=current.getNotes();
}


Toast.makeText(this, message, Toast.LENGTH_LONG).show();


return(true);
}


return(super.onOptionsItemSelected(item));
}


private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {
current=new Restaurant();
current.setName(name.getText().toString());
current.setAddress(address.getText().toString());
current.setNotes(notes.getText().toString());


switch (types.getCheckedRadioButtonId()) {
case R.id.sit_down:
current.setType("sit_down");
break;


case R.id.take_out:
current.setType("take_out");
break;


case R.id.delivery:
current.setType("delivery");
break;
}


adapter.add(current);
}
};


private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position,
long id) {
current=model.get(position);


name.setText(current.getName());
address.setText(current.getAddress());
notes.setText(current.getNotes());


65
Free download pdf