java - list item does not work in android studio -
after running application using android studio ,when clicked on list item nothing happen, wrong on code?
package com.asaad.siag.asaad; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.arrayadapter; import android.widget.listview; import static java.lang.string.valueof; public class menu extends listactivity{ string classes[] = {"mainactivity", "example 1", "example 2", "example 3", "example 4" , "example 5", "example 6"}; @override protected void oncreate(bundle v){ super.oncreate(v); setlistadapter(new arrayadapter<string>(menu.this, android.r.layout.simple_list_item_1,classes)); } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); string cheese = classes [position]; try { class ourclass = class.forname("com.asaad.siag.asaad "+ cheese); intent ourintent = new intent(menu.this, ourclass); startactivity(ourintent); }catch (classnotfoundexception e){ e.printstacktrace(); } }} i think because class.forname
you have not listview here. implement listview in xml file, on activity , follow this:
listview lv = (listview)findviewbyid(r.id.your_list_view); lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1,int position, long arg3) { //do st } });
Comments
Post a Comment