Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have json like this

{
"head": {
    "title": "Music",
    "status": "200"
},
"Info": [
    {
        "Name": "Mos Def",
        "Type": "music",
        "Results": [
            {
                "Name": "Talib Kweli",
                "Type": "music"
            },
            {
                "Name": "Black Star",
                "Type": "music"
            },
            {
                "Name": "Little Brother",
                "Type": "music"
            }
         ]
    }, 
    {
        "Name": "Mos Def",
        "Type": "Vehicles",
        "Results": [
            {
                "Name": "Chevy",
                "Type": "Car"
            },
            {
                "Name": "Ford",
                "Type": "Car"
            },
            {
                "Name": "Pontiac",
                "Type": "Car"
            }
         ]
      }
   ]
}

In my code I can get JSON Object Info to show type "Music, vehicles" in a list view . I wanna if I click Music it will show jsonObject Results - in other list view . How this solution?? thanks

share|improve this question
add comment

1 Answer

On click of setOnItemSelectedListener of your listView set adapter for another listView.

I worked on similar scenarion in my case I was getting json response for departments and corresponding Team for departments. Onclick of departments I have to show team list for selected department.I have used spinners for displaying items .Here is the sample code for that :

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, mDeptmntList);
            dataAdapter
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mDeptmntSpinner.setAdapter(dataAdapter);
            mDeptmntSpinner
                    .setOnItemSelectedListener(new OnItemSelectedListener() {

                        public void onItemSelected(AdapterView<?> arg0,
                                View arg1, int arg2, long arg3) {
                            int index = arg0.getSelectedItemPosition();
                            mSelectedDeptId = index;

                            ArrayAdapter<String> teamAdapter = new ArrayAdapter<String>(
                                    getApplicationContext(),
                                    android.R.layout.simple_spinner_item, mList
                                            .get(index));
                            teamAdapter
                                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            mTeamSpinner.setAdapter(teamAdapter);
                        }

                        public void onNothingSelected(AdapterView<?> arg0) {

                        }
                    });

this was my json response :

{
   "departmentId":"1",
   "departmentname":"HR",
   "teamlist":[
      {"teamName":"HR_S",
      "teamName":"HR_P"}
   ]
}


Code for fetching this json is :
        JSONArray array = new JSONArray(JSON response);
        JSONObject obj;
        mDeptmntList = new ArrayList<String>();
        mTeam = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < array.length(); i++) {
            obj = (JSONObject) array.get(i);
            mDeptmntList.add(i, obj.getString("departmentname"));
            JSONArray teamList = obj.getJSONArray("teamlist");
            int count = teamList.length();
            for (int j = 0; j < count; j++) {
                mTeamTempId.add(j,teamList.getJSONObject(j).getString("teamName"));
            }
        }
share|improve this answer
 
thanks , But I wanna ask how to get this value with json , –  user1920582 Jan 11 '13 at 7:25
 
edited code for it –  user1969053 Jan 11 '13 at 8:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.