Android Programming Tutorials

(Romina) #1
Splitting the Tab

spec=getTabHost().newTabSpec("tag2");
spec.setContent(R.id.details);
spec.setIndicator("Details", getResources()
.getDrawable(R.drawable.restaurant));
getTabHost().addTab(spec);


getTabHost().setCurrentTab( 0 );


list.setOnItemClickListener(onListClick);
}


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


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


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


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


adapter.add(r);
}
};


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


name.setText(r.getName());
address.setText(r.getAddress());


if (r.getType().equals("sit_down")) {
types.check(R.id.sit_down);
}
else if (r.getType().equals("take_out")) {
types.check(R.id.take_out);
}
else {
types.check(R.id.delivery);


54
Free download pdf