android - Launching an activity from the ListView -
public class listitem { public int sname; public int s_img; public string sid; } class xyz extends listactivity { . . . protected void onlistitemclick(listview l, view v, int position, long id) { //super.onlistitemclick(l, v, position, id); toast.maketext(listpage.this,items.get(position).sid,toast.length_short).show(); intent intent = new intent(v.getcontext(),displayscheme.class); startactivityforresult(intent,0); } }
i wish start new activity above xyz class. activity should start when 1 of items on list clicked. in next activity, wish display further details of "listitem" object viz. s_img , sname; there way pass on clicked listitem object next displayscheme activity ? coz there no way in next activity find out item clicked in earlier activity. in advance.
.............. edited ...............
protected void onlistitemclick(listview l, view v, int position, long id) { //super.onlistitemclick(l, v, position, id); toast.maketext(listpage.this, items.get(position).sid, toast.length_short).show(); intent intent = new intent(v.getcontext(),displayscheme.class); intent.putextra("positionidentifier",v.gettag()); startactivityforresult(intent,0); }
this edited onlistitemclick. getting error on "intent.putextra" line says "the method putextra(string, boolean) in type intent not applicable arguments (string, object)"
................. more edits.. arrayadapter................
public class myadapter extends baseadapter { layoutinflater inflater; list<listitem> items; public myadapter(activity context, list<listitem> items) { super(); this.items = items; this.inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service); } @override public int getcount() { // todo auto-generated method stub return items.size(); } @override public object getitem(int position) { // todo auto-generated method stub return null; } @override public long getitemid(int position) { // todo auto-generated method stub return 0; } @override public view getview(final int position, view convertview, viewgroup parent) { listitem item = items.get(position); view vi=convertview; if(convertview==null) vi = inflater.inflate(r.layout.list_row, null); imageview imgv = (imageview)vi.findviewbyid(r.id.s_name); imgv.setimageresource(item.sname); return vi; } }
this myadapter class, need make changes "settag()" or dat ?
this, looks good:
toast.maketext(listpage.this,items.get(position).sid,toast.length_short).show(); intent intent = new intent(v.getcontext(),displayscheme.class); startactivityforresult(intent,0);
but, instead of using v.getcontext()
suggest using this: xyz.this
.
also, if not expecting result displayscheme
activity, there no need use startactivityforresult()
. should use startactivity()
, pass intent
instance it.
if need send data intent
, simple intent.putextra(some_key_name, the_value_you_want_to send);
you.
you don't need use startactivityforresult()
if want send data activity. use when want fetch result activity.
edit:
okay, in activity should have corresponding list<listitem> items;
gather data , pass adapter right? still haven't posted code activity. see if helps. may have play around right.
toast.maketext(listpage.this,items.get(position).sid,toast.length_short).show(); intent intent = new intent(v.getcontext(),displayscheme.class); intent.putextra("some_key_name", items.get(position).sname; startactivityforresult(intent,0);
if using pojo (a setter , getter) handle data before passing list<listitem> items;
, posting , details activity can more.
Comments
Post a Comment