android - ListView with a dynamic intents that change a TextView and WebView on each call -


activity sending putextra()

@override protected void onlistitemclick(listview l, view v, int position, long id) {     super.onlistitemclick(l, v, position, id);     final intent intent = new intent();     // set different intents based on item clicked:      switch (position)     {         case activity_0:             intent.putextra("value1", "display text!");             intent.setclass(this, com.a.someclass.class); }     startactivityforresult(intent, position); } 

activity receiving putextra()

@override protected void oncreate(bundle bundle) {     // todo auto-generated method stub     super.oncreate(bundle);     setcontentview(r.layout.information);     bundle extras = getintent().getextras();     if (extras == null) {         return;     }     string value1 = extras.getstring("value1");      if (value1 != null) {         informationtitle = (textview)findviewbyid(r.id.informationtitle);         informationtext = (webview)findviewbyid(r.id.informationtext);         informationtitle.settext(value1);     } 

original message:

i have been searching everywhere tutorial on this, have posted code online people can @ have not found needed.

i new , trying have list of items linked 1 class has dynamic textview used title , webview content, , when item clicked on list open new activity/intent , pass arguments change textview , webview accordingly.

i know how open new activity making new class each item on list pretty sure there easier way can reuse 1 class , keep changing textview , webview. reason because have 15 items on list, expand overtime dont want making 50-60 different classes open each new item.

if point me right tutorial or give me insight on here really appreciate it!

thank you

to accomplish that, would, instead of using different intent each list item, call same activity same intent, pass extras along it.

let's say, instance, want pass different string depending on list item clicked. want to

myintent.putextra(string key, string value); startactivity(myintent); 

the activity start intent able grab these extras in oncreate() using

bundle extras = getintent().getextras(); 

and access extras put in intent using methods outlined here. way can use single activity list items have activity display different information based on values.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -