android - cast a class to an activity -
i'm trying create listview wich enable open 2 other activities created before. i've got problem intent. i'm quite sure understand lactivity activity wich exists. explain me why?
thank you!!
public listmenu extends activity { private listview malistview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.list); // create list of elements list<elementofconstruction> liste = new arraylist<elementofconstruction>(); string columns = null; class<?> calculcolumns = null; elementofconstruction columns = new elementofconstruction(columns, 0, r.drawable.columns, calculcolumns, 100); liste.add(columns); string beam1 = null; class<?> calculbeam = null; elementofconstruction beam1 = new elementofconstruction(beam1, 0, r.drawable.beam1, calculbeam, 200); //récupération de la listview créée dans le fichier main.xml malistview = (listview) findviewbyid(r.id.malistview); arrayadapter<elementofconstruction> adapter = new arrayadapter<elementofconstruction>(listmenu.this, r.layout.row_list, r.id.name, liste); // affecter l'adapter à notre listview malistview.setadapter(adapter); malistview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { //on récupère le titre de l'item dans un elementofconstruction //start new activity //récupération de l’item sélectionné elementofconstruction element = (elementofconstruction)malistview.getadapter().getitem(position); class<?> lactivity = element.getactivity(); int numidentification = element.getnumidentification(); //open new activity intent intent = new intent(listmenu.this, lactivity.class); startactivityforresult(intent,numidentification); } }); }}
you passing class of activity intent, not activity itself.
change line:
class<?> lactivity = element.getactivity();
to:
activity lactivity = element.getactivity();
Comments
Post a Comment