android - How to use returned arraylist?How to retrieve data from arraylist? -
in following code,i saving 3 values fun_id,fun_logo,fun_req of class use.in code arraylist returned,now want retrieve fun_id,fun_logo,fun_req.i want add fun_logo imagearray.i know how use class use retreving data.i learning small idea bout android.
arraylist<use> stringarraylist = null; arraylist<use> res = null; arraylist<string> linklist = null; string getdetailsurl; string link []; string[] ar; use[] getalldet; public string imagearray[]; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); new getdetailsfromweb().execute(); list=(listview)findviewbyid(r.id.listview1); // adapter=new myadpter(this, imagearray); list.setadapter(adapter); } public class getdetailsfromweb extends asynctask<string,void,string> { string result = ""; @override protected string doinbackground(string... params) { getdetailsurl=webcall.getdet(); if(getdetailsurl!=null) { result = "success"; } else { result = "failure"; } return result; } @override protected void onpostexecute(string result) { res = new arraylist<use>(); try { if (result.contentequals("success")) { res=passdetails(); system.out.println("lsize " + res.size()); for(int i=0;i<res.size();i++) { // retreive value should here imagearray[i]=obj.funlogo; system.out.println("logo " + imagearray[i]); } } else { } } catch (exception e1) { e1.printstacktrace(); } } public arraylist<use> passdetails() { jsonarray array = null; stringarraylist = new arraylist<use>(); linklist= new arraylist<string>(); use usee; try { array = new jsonarray(getdetailsurl); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } for(int = 0;i <array.length() ;i++ ) { string fun_id= null; string fun_logo= null; string fun_req = null; try { fun_id = array.getjsonobject(i).getstring("up_id"); system.out.println("up_id " + fun_id); fun_logo=array.getjsonobject(i).getstring("logo"); system.out.println("logo " + fun_logo); fun_req=array.getjsonobject(i).getstring("requirements"); system.out.println("req " + fun_req); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } usee=new use(); usee.funid=fun_id; system.out.println("fun " + usee.funid); usee.funlogo=fun_logo; system.out.println("fun " + usee.funlogo); usee.funreq=fun_req; system.out.println("fun " + usee.funreq); linklist.add(fun_logo); stringarraylist.add(usee); } return stringarraylist; } }
use.java
public class use { public static string funid; public string funlogo; public string funreq; }
- define
use
class getter , setter methods. define method
getfunlogos()
inuse
class return image array of fun logos. access method wherever want.protected string[] getfunlogos(arraylist<use> listfunlogos) { for(int i=0;i<res.size();i++) { // retreive value should here imagearray[i]=obj.funlogo; system.out.println("logo " + imagearray[i]); } }