Note that there are some explanatory texts on larger screens.

plurals
  1. POExpandable ListView with JSON Data in android
    primarykey
    data
    text
    <p>I have a big problem and I have been searching on the web to have a good solution for this problem but I couldn't find any approach for this problem so I want help. </p> <p>I need to use expandable list view which get data from server (JSON Array) and i have categories, <code>GroupData</code> and its items, <code>ChildData</code>. I don't know how to get the child data for each parent group... i need something like <code>SimpleCursorTreeAdapter</code> but i didn't find anything. </p> <p>This is what i reach for till now but it's not working so please help me:</p> <pre><code> static ArrayList&lt;HashMap&lt;String, String&gt;&gt; mapList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); static ArrayList&lt;HashMap&lt;String, String&gt;&gt; catItemsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); static ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; ItemsList = new ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt;(); static ListView order_list; static ExpandableListView order_items_list; static SimpleAdapter adapter,ItemsAdapter; protected void BindOrederItemList(final int order_id) { // TODO Auto-generated method stub //select all categories from order items where order_id =?? //select items where category=?? JSONObject params = new JSONObject(); //int no_pepole=Integer.valueOf(noOfGest_txt.getText().toString()); try { // params.put("order_status",myStatus); int rest_id=prefs.getInt("Rest_id", 0); params.put("order_id", order_id); params.put("lang_id", 1); params.put("rest_id", rest_id ); //params.put("order_status", 0); // params.put("noOfpepole",number_of_guest); } catch(Exception e) { e.printStackTrace(); } String Url="http://192.168.3.113/mywebservices.php?op=GetOrderCategory"; GetNetworkData.OnPostExecuteListener listener=new GetNetworkData.OnPostExecuteListener() { @Override public void onPostExecute(String result) { // TODO Auto-generated method stub if (result!=null) { try { catItemsList.clear(); JSONArray jArray = new JSONArray(result); ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; list=new ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt;(); // ArrayList&lt;Integer&gt; category=new ArrayList&lt;Integer&gt;(); for (int i = 0; i &lt; jArray.length(); i++) { HashMap&lt;String, String&gt; Catmap = new HashMap&lt;String, String&gt;(); JSONObject e = jArray.getJSONObject(i); id=e.getInt("order_id"); cat_name=e.getString("cat_name"); cat_id=e.getInt("cat_id"); Catmap.put("cat_id",String.valueOf(cat_id)); Catmap.put("cat_name", cat_name); catItemsList.add(Catmap); Log.i("Insid For Loop", "order ID "+order_id); list= BindCatItems(cat_id, order_id); Log.i("Insid For Loop", "Child size = "+list.size()); } // Log.i("Insid For Loop", "Group size = "+catItemsList.size()); SimpleExpandableListAdapter expandListAdapter= new SimpleExpandableListAdapter(getActivity(), catItemsList, R.layout.group_item, new String[] {"cat_name"},new int[]{R.id.lbl_cat_group}, list, R.layout.category_row, new String[]{"item_name"}, new int[]{R.id.txt_category_row}); order_items_list.setAdapter(expandListAdapter); // Log.i("Bind item", "CAT SIZE "+catItemsList.size()); } catch(Exception e) { e.printStackTrace(); } } } }; try { GetNetworkData task = new GetNetworkData(Url,params,listener); task.execute(); } catch(Exception e) { e.printStackTrace(); } } protected ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; BindCatItems(int cat_id,int order_id) { // TODO Auto-generated method stub JSONObject params = new JSONObject(); //int no_pepole=Integer.valueOf(noOfGest_txt.getText().toString()); try { // params.put("order_status",myStatus); int rest_id=prefs.getInt("Rest_id", 0); params.put("order_id", order_id); params.put("lang_id", 1); params.put("cat_id",cat_id ); //params.put("order_status", 0); // params.put("noOfpepole",number_of_guest); } catch(Exception e) { e.printStackTrace(); } String Url="http://192.168.3.113/mywebservices.php?op=GetOrderItems"; GetNetworkData.OnPostExecuteListener listener=new GetNetworkData.OnPostExecuteListener() { @Override public void onPostExecute(String result) { // TODO Auto-generated method stub if (result!=null) { try { Log.i("log bind","Inside Bind Category items"); // catItemsList.clear(); mapList.clear(); JSONArray jArray = new JSONArray(result); for (int i = 0; i &lt; jArray.length(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); JSONObject e = jArray.getJSONObject(i); int id=e.getInt("item_id"); if (id==0) { } else { map.put("item_id",String.valueOf(e.getInt("item_id"))); map.put("oi_id", String.valueOf(e.getInt("oi_id"))); map.put("item_name", e.getString("item_name")); map.put("quantity",String.valueOf( e.getString("quantity"))); map.put("price", String.valueOf("price")); mapList.add(map); } } ItemsList.add(mapList); // Log.i("Bind Item Order", "CAT SIZE "+catItemsList.size()); /* ItemsAdapter=new SimpleAdapter(getActivity(), catItemsList, R.layout.list_item, new String[] {"item_name"}, new int[]{R.id.list_item_title}); */ // Log.i("Add Section","ItemsAdapter count= "+ItemsAdapter.getCount()); //order_list.setAdapter(adapter); //adapter.notifyDataSetChanged(); } catch(Exception e) { e.printStackTrace(); } } } }; try { GetNetworkData task = new GetNetworkData(Url,params,listener); task.execute(); } catch(Exception e) { e.printStackTrace(); } return ItemsList; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload