I am building an android application where I am parsing the raw array to my baseAdapter of listview. Like :
I take global variable
ListView l1; String[] t1={"video1","video2"}; String[] d1={"lesson1","lesson2"}; int[] i1 ={R.drawable.ic_launcher,R.drawable.ic_launcher};
Initialy listview.
l1=(ListView)findViewById(R.id.list); l1.setAdapter(new dataListAdapter(t1,d1,i1));
- Use baseAdapter Class
class dataListAdapter extends BaseAdapter { String[] Title, Detail; int[] imge; dataListAdapter() { Title = null; Detail = null; imge=null; } public dataListAdapter(String[] text, String[] text1,int[] text3) { Title = text; Detail = text1; imge = text3; } public int getCount() { // TODO Auto-generated method stub return Title.length; } public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row; row = inflater.inflate(R.layout.custom, parent, false); TextView title, detail; ImageView i1; title = (TextView) row.findViewById(R.id.title); detail = (TextView) row.findViewById(R.id.detail); i1=(ImageView)row.findViewById(R.id.img); title.setText(Title[position]); detail.setText(Detail[position]); i1.setImageResource(imge[position]); return (row); } }
This is working fine for only static data. Now I am parsing the value using Json like
try { jsonObj = new JSONObject(result); array = jsonObj.getJSONArray("list"); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); profilePic= ""+obj.getString(TAG_PROFILEPIC); firstName= ""+obj.getString(TAG_FIRSTNAME); lastName= ""+obj.getString(TAB_LASTNAME); // status= ""+obj.getInt("status"); HashMap<String, String> contact = new HashMap<String, String>(); contact.put(TAG_PROFILEPIC, profilePic); contact.put(TAG_FIRSTNAME, firstName); contact.put(TAB_LASTNAME, lastName); // do code for adding these values to adapter. } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Now, I need to parse this Json value in place of the static data of baseAdapter.
How can I do this?