Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6705355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:39+00:00 2026-05-26T07:23:39+00:00

I am working on a project with parsing JSON from url to ExpandableListView. Depending

  • 0

I am working on a project with parsing JSON from url to ExpandableListView. Depending on the “status” tag value (active or pending) , will be placing records accordingly to to different groups “Active” and “Pending”. Everything is working fine.

My Problem is when I click on a child inside the second group which should show different data, but I am getting data the data from first group child.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnGroupClickListener;

public class ExpandableActivity1 extends ExpandableListActivity {
    JSONArray jArray = null;
    JSONObject json_data = null;
    TextView txtMLSID;
        List<Map<String, String>> child1;
     List<Map<String, String>> child2;

       @Override
       public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);



    List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
    Map<String, String> group1 = new HashMap<String, String>();
    group1.put("group", " Active");
    groups.add(group1);
    Map<String, String> group2 = new HashMap<String, String>();
    group2.put("group", " Pending");
    groups.add(group2);
    child1 = new ArrayList<Map<String, String>>();
    child2 = new ArrayList<Map<String, String>>();




    String url ="http://stage.realtylog.net/iPhone/functions.php?username=hussain16&act=listing";

    String  json = JSONfunctions.getJSONfromURL(url);




 try{




 jArray = new JSONArray(json);

 for(int i=0;i<jArray.length() ;i++){                       


     Map<String, String> childdata1 = new HashMap<String, String>();

        JSONObject e = jArray.getJSONObject(i);

        String status = e.getString("2");
         Log.e("log_tag","Status: "+status); 

         if (status.contains("active")){
             Log.e("log_tag","StatusActive: "+status); 

             childdata1.put("0",  String.valueOf(i+1)+" "+ e.getString("mlsid"));



                child1.add(childdata1); 

         }else if(status.contains("pending")){
             Log.e("log_tag","StatusPending: "+status); 



                Map<String, String> childdata2= new HashMap<String, String>();
                childdata2.put("0",  String.valueOf(i+1)+" "+ e.getString("mlsid"));


                child2.add(childdata2);




         }


    }   

  }catch(JSONException e)        {
 Log.e("log_tag", "Error parsing data "+e.toString());
  }





       List<List<Map<String, String>>> childs = new ArrayList<List<Map<String,   String>>>();
        childs.add(child1);
        childs.add(child2);




    SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
            this, groups, R.layout.groups, new String[] { "group" },
            new int[] { R.id.group }, childs, R.layout.childs,
            new String[] { "0"}, new int[] { R.id.child });
        setListAdapter(adapter);
        }

     @Override
    public boolean setSelectedChild(int groupPosition, int childPosition,
             boolean shouldExpandGroup) {
        //do something
       Log.e("log_tag","setSelectedChild: "); 
         return super.setSelectedChild(groupPosition, childPosition,
                  shouldExpandGroup);
   }

    @Override
    public void setSelectedGroup(int groupPosition) {
    //do something

       Log.e("log_tag","setSelectedGroup: "); 
        super.setSelectedGroup(groupPosition);
}


**//Here I am Getting problem**

@SuppressWarnings("unchecked")
public boolean onChildClick(
           ExpandableListView parent, 
           View v, 
           int groupPosition,
           int childPosition,
           long id) {
Log.d( "LOG_TAG", "onChildClick: "+"GROUP: "+groupPosition+"   CHILD Position:  "+ childPosition);

HashMap<String, String> o =    (HashMap<String, String>)  parent.getItemAtPosition(childPosition+1);           

              String val = o.get("0");
          Log.d( "LOG_TAG", "selected value :  "+val  );




           return false;

       }






 }

LogCat Info when public boolean onChildClick () called :

10-20 11:24:28.004: DEBUG/LOG_TAG(1652): onChildClick: GROUP: 0   CHILD Position:  0
10-20 11:24:28.004: DEBUG/LOG_TAG(1652): selected value :  1 555
10-20 11:24:42.454: DEBUG/LOG_TAG(1652): onChildClick: GROUP: 1   CHILD Position:  0
10-20 11:24:42.454: DEBUG/LOG_TAG(1652): selected value :  1 555

Logcat shows that I am getting same value for group1(Active) and group2(Pending)

I need specific value for each child view based on click.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:23:40+00:00Added an answer on May 26, 2026 at 7:23 am

    You have to use Adapter’s getChild(groupPosition, childPosition) method to retrieve the instance of child and the cast it to your Map and get it working.

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
    
        Toast.makeText(this, (String)((Map<String, String>)
                    adapter.getChild(groupPosition, childPosition)).get("lalit"),
                                                          Toast.LENGTH_LONG).show();
        return super.onChildClick(parent, v, groupPosition, childPosition, id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project that will involve parsing HTML. After searching around,
I am working on a project in Android now that involves parsing XML from
I'm parsing image paths from CSS files for a project I'm working on and
I'm working on a project that involves parsing a large csv formatted file in
I am working on a project that requires reading text files, extracting data from
I am working on a project where the app parses data from an XML
I am working on a project which basically involves parsing and storing information about
I am working on a project that requires the parsing of formatting tags. By
i'm working on parsing a text project where in , i have to match
Working on a [rails] project, I've started playing around with RSS parsing. I notice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.