java - I have got a ListFragment with some options but ItemClick doesn't work -
i have tried lot of solutions found in web of them works, have got code:
public class cambiar_ciudad extends listfragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.lay_cambiar_ciudad, container, false); string[] values = new string[] {"barcelona", "madrid", "sevilla", "valencia" }; arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_1, values); setlistadapter(adapter); return rootview; } }
that's code shows me list
("barcelona", "madrid", "sevilla", "valencia")
, when push 1 of them send me new layout.
i did in not fragment , works code:
ciudades = new string[]{"badajoz","barcelona", "madrid", "sevilla", "valencia"}; arrayadapter<string> adapter; adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1, ciudades); listview lv = (listview) findviewbyid(r.id.listview); lv.setadapter(adapter); lv.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { // when clicked, show toast textview text if (position == 0) { intent myintent = new intent(view.getcontext(), menu_principal.class); startactivityforresult(myintent, 0); } if (position == 1) { intent myintent = new intent(view.getcontext(), menu_principal.class); startactivityforresult(myintent, 0); } if (position == 2) { intent myintent = new intent(view.getcontext(), menu_principal.class); startactivityforresult(myintent, 0); } if (position == 3) { intent myintent = new intent(view.getcontext(), menu_principal.class); startactivityforresult(myintent, 0); } if (position == 4) { intent myintent = new intent(view.getcontext(), menu_principal.class); startactivityforresult(myintent, 0); } } });
but in listfragment not know how link options menu_principal.class
i hope of can solve it, lot!
put code in your
@override public void onlistitemclick(listview l, view v, int position, long id){ context context = getactivity(); // when clicked, show toast textview text if (position == 0) { intent myintent = new intent(context, menu_principal.class); context.startactivityforresult(myintent, 0); } if (position == 1) { intent myintent = new intent(context, menu_principal.class); context.startactivityforresult(myintent, 0); } if (position == 2) { intent myintent = new intent(context, menu_principal.class); context.startactivityforresult(myintent, 0); } if (position == 3) { intent myintent = new intent(context, menu_principal.class); context.startactivityforresult(myintent, 0); } if (position == 4) { intent myintent = new intent(context, menu_principal.class); context.startactivityforresult(myintent, 0); } }
Comments
Post a Comment