I’m making a base class for my androids screen, it is has a list control. Is there a way for when the base class’s onListItemClick gets called, saying a list item was selected. It could call a function in the parent class??
Code:
public class cHome extends cBase {
String[] MyItems={
"Gate Directions",
"Food & Beverges",
"Shjops",
"Banking",
"Official Agencies",
"Amenities & Services",
"Restrooms"
};
public void onCreate(Bundle icicle) {
super.onCreate(icicle, MyItems);
// Display=MyItems;
}
Code:
public class cBase extends ListActivity {
String[] items={"CASUAL","DRESSES","CAREER","OUTWEAR","FOOTWEAR",
"JEWELRY","ACCESSORIES"};
String[] Display;
public void onCreate(Bundle icicle, String[] items2) {
Display=items2;
super.onCreate(icicle);
setContentView(R.layout.baselayout);
setListAdapter(new IconicAdapter(this));
// selection=(TextView)findViewById(R.id.selection);
// set values in header
// set header
TextView mFlight = (TextView)findViewById(R.id.idFlyerFlightNumber);
mFlight.setText( cGlobals.mFlightNumber);
TextView mDes = (TextView)findViewById(R.id.idFlyerDestanation);
mDes.setText( cGlobals.mDestanation);
}
class IconicAdapter extends ArrayAdapter {
Activity context;
IconicAdapter(Activity context) {
super(context, R.layout.row, Display);
this.context=context;
}
public View getView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View row=inflater.inflate(R.layout.row, null);
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(Display[position]);
ImageView icon=(ImageView)row.findViewById(R.id.icon);
// String[] items={"CASUAL","DR ESSES","CAREER","OUTWEAR","FOOTWEAR",
// "JEWELRY","ACCESSORIES"};
switch(position)
{
case 0:
// icon.setImageResource(R.drawable.formobile_items);
break;
case 1:
// icon.setImageResource(R.drawable.fashion_dress);
break;
case 2:
// icon.setImageResource(R.drawable.fashion_career);
break;
case 3:
// icon.setImageResource(R.drawable.fashion_outwear);
break;
case 4:
// icon.setImageResource(R.drawable.fashion_footwear);
break;
case 5:
// icon.setImageResource(R.drawable.fashion_jewelry);
break;
case 6:
// icon.setImageResource(R.drawable.fashion_accessories);
break;
}
return(row);
}
}
}
You can override
onListItemClickin your child class and just callsuper.onListItemClickon it. Or don’t override it andonListItemClickmethod of base class will be called automatically when item in the list selected.