java - How to fill ListView with Adapters -


i'm aware simple question i'm newbie in android development please go easy on me.
problem have in 1 of fragments (asynctask specifically) lays in main activity. asynctask sends out data php script returns according data in json format. processed , saved jsonlist array. until post execute works fine data downloaded, processed etc. when program reaches post execute problems start pop out. , i'm unable list out data jsonlist listview

    //setting array     arraylist<hashmap<string, string>> jsonlist = new arraylist<hashmap<string, string>>();     //creating list view variable     listview listview;     //define work in progress dialog     private progressdialog mprogressdialog;    private class progresstask extends asynctask<string, void, boolean> {         @override         protected void onpreexecute() {             super.onpreexecute();              // create progressdialog             mprogressdialog = new progressdialog(getactivity());              // set progressdialog title             mprogressdialog.settitle("please wait");              // set progressdialog message             mprogressdialog.setmessage("fetching data...");             mprogressdialog.setindeterminate(false);          }          @override         protected boolean doinbackground(string... params) {             //to in background             //define variable of json parser type             jsonparser jparser = new jsonparser();              //pass url json parser class fetch , save array variable             jsonarray json = jparser.getjsonfromurl(url);              //loop 0 length of array increasing 1             (int = 0; < json.length(); i++) {                  //try , catch routine prevent crashes                 try {                     //get object defined in { ... } in original json file                     jsonobject c = json.getjsonobject(i);                      //separate object obtaining values each of sections                     string vtitle = c.getstring(title);                     string vcontent = c.getstring(content);                     string vuser = c.getstring(user);                      hashmap<string, string> map = new hashmap<string, string>();                      //fill array data extracted                     map.put(title, vtitle);                     map.put(content, vcontent);                     map.put(user, vuser);                      //add values jsonlist                     jsonlist.add(map);                  } catch (jsonexception e)                 {                     //in case of error stack trace returned                     e.printstacktrace();                 }             }             //once has been done return null value             return null;         }         @override         protected void onpostexecute(boolean aboolean) {             //insert data downloaded through list adapter             listadapter adapter = new simpleadapter(getactivity(), jsonlist, r.layout.list_activity, new string[] { title, content, user }, new int[] { r.id.title, r.id.content, r.id.user });              // locate listview              //listview = (listview) findviewbyid(r.id.list);              // set adapter listview             //listview.setadapter(adapter);              //get rid off dialog when operation of fetching data has been done             if (mprogressdialog.isshowing()) {                 mprogressdialog.dismiss();             }         }     } 

as can see have tried commented code listview = (listview) findviewbyid(r.id.list); returns following error:

cannot resolve method findviewbyid(int)

which prevents me executing program. upsetting because literally have data need in array 1 line of code stops me displaying it.

i have tried:

    listadapter adapter = new simpleadapter(context, jsonlist, r.layout.list_activity, new string[] { title, content, user }, new int[] { r.id.title, r.id.content, r.id.user });     setlistadapter(adapter);     lv = getlistview(); 

but in previous case error of unresolved method returned. due fact fragment extended fragment , adding crashes it

public class fragment2 extends fragment, listactivity {...} 

add code in fragment2 class.

private listview listview;  @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     view v = inflater.inflate(r.layout.your_fragment_layout, container, false);      listview = (listview) v.findviewbyid(r.id.r.id.list);     return v; } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -