我正在爲我的androids屏幕做一個基類,它有一個列表控件。有沒有辦法讓基類的onListItemClick被調用,並說選擇了一個列表項。它可以在父類中調用一個函數?有沒有辦法在java中的父類中調用函數?
代碼:
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;
}
代碼:
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);
}
}
}
你應該指明你要調用什麼方法。 – Clint