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

  • SEARCH
  • Home
  • 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 8318137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:51:22+00:00 2026-06-08T21:51:22+00:00

I have been stuck in this problem for two weeks, I hope someone could

  • 0

I have been stuck in this problem for two weeks, I hope someone could help me out. Thanks in advance.

I want to create a view in an activity which consists of a header view and a list view at the bottom. So far, I have been successful in getting the data from JSON to the listView since most of the tutorials out there are only about JSON and listView.

My question is, how can I get the below data to display on the header, a simple view(non listView) or even the view I want…

the JSON file

{
 "photos" : [
  {
     "thumbnail" : "http://www.myserver.com/01.jpg",
  },
  {
     "thumbnail" : "http://www.myserver.com/02.jpg",
  },
  {
     "thumbnail" : "http://www.myserver.com/03.jpg",
  },
],
"info" : [
  {
     "id" : "1",
     "description" : "My White Toyota",
     "country" : "Japan",
     "year" : "1982"
   }
 ];
"owners" : [
   {
     "ownerid" : "5633432",
     "name" : "Jackson",
     "year_own" : "1982-1985"
    },
    {
     "ownerid" : "76832",
     "name" : "Kurt",
     "year_own" : "1986-1995"
    },
    {
     "ownerid" : "236471",
     "name" : "Alma",
     "year_own" : "1999-2005"
    }
   ]
}

the List class

public class car_detail {
    private List<CAR_INFO_MODEL> photos;
    private List<CAR_INFO_MODEL> info;
    private List<CAR_INFO_MODEL> owners;

public List<CAR_INFO_MODEL> getPhotos(){
    return photos;
}
public void setPhotoList(List<CAR_INFO_MODEL> photos){
    this.photos = photos;
}

    public List<CAR_INFO_MODEL> getInfos(){
    return info;
}
public void setInfoList(List<CAR_INFO_MODEL> info){
    this.info = info;
}

    public List<CAR_INFO_MODEL> getOwners(){
    return owners;
}
public void setOwnerList(List<CAR_INFO_MODEL> owners){
    this.owners = owners;
}
}

the model class

public class CAR_INFO_MODEL {
private String description;
private String year;

private String thumbnail;

private String name;
private String year_own;

public String getDesc() {
    return description;
}
public void setDesc(String description) {
    this.description = description; 
    }
    public String getYear() {
    return year;
}
public void setYear(String year) {
    this.year = year; 
    }
    public String getPhoto() {
    return thumbnail;
}
public void setPhoto(String thumbnail) {
    this.thumbnail = thumbnail; 
    }
    public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name; 
    }
    public String getYearown() {
    return year_own;
}
public void setYearown(String year_own) {
    this.year_own = year_own; 
    }
}

the activity class (I use AsyncTask to query and get the JSON respose), I can successfully get the info object from the JSON, but no idea on how to get the photos and owners.

 public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cardetail_layout);

    lv = (ListView) findViewById(R.id.list_cardetail);

    carArray = new ArrayList<CAR_INFO_MODEL>();
    carDetailAdapter = new carDetailAdapter(carActivity.this, R.layout.caritem_layout, infoArray);
            lv.setAdapter(carDetailAdapter);  
            try {
                new DealSync().execute("http://www.myserver.com/carsquery/");
            } catch(Exception e) {}
 }


 String json = client.getResponse();
 list = new Gson().fromJson(json, car_detail.class); 

 return list;

 protected void onPostExecute(car_detail infolist) {

        for(CAR_INFO_MODEL lm : infolist.getInfo())
        {
            infoArray.add(lm);
        }
        carDetailAdapter.notifyDataSetChanged();
    }

the adapter class (I can get the info to show as a single item list, but I don’t know how to get the photos and the owners (bottom listview) from the data and show it.)

public class carDetailAdapter extends ArrayAdapter<CAR_INFO_MODEL> {
int resource;
String response;
Context context;
private LayoutInflater dInflater;

public carDetailAdapter(Context context, int resource, List<CAR_INFO_MODEL> objects) {
        super(context, resource, objects);
        this.resource = resource;
        dInflater = LayoutInflater.from(context);
}
static class ViewHolder {

    TextView description;

}
public View getView(int position, View convertView, ViewGroup parent)
{
    ViewHolder holder;
    CAR_INFO_MODEL lm = (CAR_INFO_MODEL) getItem(position);

    //Inflate the view
    if(convertView==null)
    {
        convertView = dInflater.inflate(R.layout.carDetail_layout, null);
        holder = new ViewHolder();
        holder.description = (TextView) convertView.findViewById(R.id.cardesc);
        convertView.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.description.setText(lm.getDesc());

    return convertView;
}

}

This may sound complex, just hope someone could give me a help. Thank you so much

  • 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-06-08T21:51:23+00:00Added an answer on June 8, 2026 at 9:51 pm

    there are some issues i noticed in your logic

    • first of all the JSON string you are using is not JSON formatted. this same string cannot be parsed by GSON parser.

    issues :

    • there is an additional comma at the end of thumbnail variable of photo
    • The info object ends with ; rather than ,

    corrected JSON string is here:

    {
     "photos" : [
      {
         "thumbnail" : "http://www.myserver.com/01.jpg"
      },
      {
         "thumbnail" : "http://www.myserver.com/02.jpg"
      },
      {
         "thumbnail" : "http://www.myserver.com/03.jpg"
      }
    ],
    "info" : [
      {
         "id" : "1",
         "description" : "My White Toyota",
         "country" : "Japan",
         "year" : "1982"
       }
     ],
    "owners" : [
       {
         "ownerid" : "5633432",
         "name" : "Jackson",
         "year_own" : "1982-1985"
        },
        {
         "ownerid" : "76832",
         "name" : "Kurt",
         "year_own" : "1986-1995"
        },
        {
         "ownerid" : "236471",
         "name" : "Alma",
         "year_own" : "1999-2005"
        }
       ]
    }
    

    now the logical mistakes i found

    • your CarDetails JSON data contains three objects. 1. List of Photos 2. An Info object and 3. List of Owners
    • But your implementation deals it as a three CAR_INFO_MODEL Lists with all data in this class. By doing this, all categorization present in your JSON has been lost.
    • This is your problem here

    To solve this, categorize your data as JSON represents it. this is shown below

    The Photo class

    public class Photo {
    
        /**
         * Constructor for Photo.
         * @param thumbnail <tt></tt>
         */
        public Photo(String thumbnail) {
            super();
            this.thumbnail = thumbnail;
        }
    
        private String thumbnail;
    
        /**
         * Gets the thumbnail.
         * 
         * @return <tt> the thumbnail.</tt>
         */
        public String getThumbnail() {
            return thumbnail;
        }
    
        /**
         * Sets the thumbnail.
         *
         * @param thumbnail <tt> the thumbnail to set.</tt>
         */
        public void setThumbnail(String thumbnail) {
            this.thumbnail = thumbnail;
        }
    
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Photo [thumbnail=" + thumbnail + "]";
        }
    
    
    
    }
    

    the Info class

    public class Info {
        /*"id" : "1",
         "description" : "My White Toyota",
         "country" : "Japan",
         "year" : "1982"
    
         * */
    
        private String id;
        /**
         * Constructor for Info.
         * @param id
         * @param description
         * @param country
         * @param year <tt></tt>
         */
        public Info(String id, String description, String country, String year) {
            super();
            this.id = id;
            this.description = description;
            this.country = country;
            this.year = year;
        }
        private String description;
        private String country;
        private String year;
        /**
         * Gets the id.
         * 
         * @return <tt> the id.</tt>
         */
        public String getId() {
            return id;
        }
        /**
         * Sets the id.
         *
         * @param id <tt> the id to set.</tt>
         */
        public void setId(String id) {
            this.id = id;
        }
        /**
         * Gets the description.
         * 
         * @return <tt> the description.</tt>
         */
        public String getDescription() {
            return description;
        }
        /**
         * Sets the description.
         *
         * @param description <tt> the description to set.</tt>
         */
        public void setDescription(String description) {
            this.description = description;
        }
        /**
         * Gets the country.
         * 
         * @return <tt> the country.</tt>
         */
        public String getCountry() {
            return country;
        }
        /**
         * Sets the country.
         *
         * @param country <tt> the country to set.</tt>
         */
        public void setCountry(String country) {
            this.country = country;
        }
        /**
         * Gets the year.
         * 
         * @return <tt> the year.</tt>
         */
        public String getYear() {
            return year;
        }
        /**
         * Sets the year.
         *
         * @param year <tt> the year to set.</tt>
         */
        public void setYear(String year) {
            this.year = year;
        }
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Info [id=" + id + ", description=" + description + ", country="
                    + country + ", year=" + year + "]";
        }
    
    
    
    }
    

    the ‘Owner’ class

    public class Owner {
        /*
         * "ownerid" : "5633432",
         "name" : "Jackson",
         "year_own" : "1982-1985"
    
         * */
    
        private String ownerid;
        /**
         * Constructor for Owner.
         * @param ownerid
         * @param name
         * @param year_own <tt></tt>
         */
        public Owner(String ownerid, String name, String year_own) {
            super();
            this.ownerid = ownerid;
            this.name = name;
            this.year_own = year_own;
        }
        private String name;
        private String year_own;
        /**
         * Gets the ownerid.
         * 
         * @return <tt> the ownerid.</tt>
         */
        public String getOwnerid() {
            return ownerid;
        }
        /**
         * Sets the ownerid.
         *
         * @param ownerid <tt> the ownerid to set.</tt>
         */
        public void setOwnerid(String ownerid) {
            this.ownerid = ownerid;
        }
        /**
         * Gets the name.
         * 
         * @return <tt> the name.</tt>
         */
        public String getName() {
            return name;
        }
        /**
         * Sets the name.
         *
         * @param name <tt> the name to set.</tt>
         */
        public void setName(String name) {
            this.name = name;
        }
        /**
         * Gets the year_own.
         * 
         * @return <tt> the year_own.</tt>
         */
        public String getYear_own() {
            return year_own;
        }
        /**
         * Sets the year_own.
         *
         * @param year_own <tt> the year_own to set.</tt>
         */
        public void setYear_own(String year_own) {
            this.year_own = year_own;
        }
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "Owner [ownerid=" + ownerid + ", name=" + name + ", year_own="
                    + year_own + "]";
        }
    
    
    }
    

    and finally the CarDetail class

    public class CarDetail {
    
        private List<Photo> photos;
        private List<Info> info;
        private List<Owner> owners;
        /**
         * Gets the photos.
         * 
         * @return <tt> the photos.</tt>
         */
        public List<Photo> getPhotos() {
            return photos;
        }
        /**
         * Sets the photos.
         *
         * @param photos <tt> the photos to set.</tt>
         */
        public void setPhotos(List<Photo> photos) {
            this.photos = photos;
        }
        /**
         * Gets the info.
         * 
         * @return <tt> the info.</tt>
         */
        public List<Info> getInfo() {
            return info;
        }
        /**
         * Sets the info.
         *
         * @param info <tt> the info to set.</tt>
         */
        public void setInfo(List<Info> info) {
            this.info = info;
        }
        /**
         * Gets the owners.
         * 
         * @return <tt> the owners.</tt>
         */
        public List<Owner> getOwners() {
            return owners;
        }
        /**
         * Sets the owners.
         *
         * @param owners <tt> the owners to set.</tt>
         */
        public void setOwners(List<Owner> owners) {
            this.owners = owners;
        }
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return "CarDetail [photos=" + photos + ", info=" + info + ", owners="
                    + owners + "]";
        }
    
    
    
    }
    

    and use these classes as below to parse and get the details stored in each objects (ie, photo, owner and info)

    String json = "{" + 
    " \"photos\" : [" + 
    "  {" + 
    "     \"thumbnail\" : \"http://www.myserver.com/01.jpg\"" + 
    "  }," + 
    "  {" + 
    "     \"thumbnail\" : \"http://www.myserver.com/02.jpg\"" + 
    "  }," + 
    "  {" + 
    "     \"thumbnail\" : \"http://www.myserver.com/03.jpg\"" + 
    "  }" + 
    "]," + 
    "\"info\" : [" + 
    "  {" + 
    "     \"id\" : \"1\"," + 
    "     \"description\" : \"My White Toyota\"," + 
    "     \"country\" : \"Japan\"," + 
    "     \"year\" : \"1982\"" + 
    "   }" + 
    " ]," + 
    "\"owners\" : [" + 
    "   {" + 
    "     \"ownerid\" : \"5633432\"," + 
    "     \"name\" : \"Jackson\"," + 
    "     \"year_own\" : \"1982-1985\"" + 
    "    }," + 
    "    {" + 
    "     \"ownerid\" : \"76832\"," + 
    "     \"name\" : \"Kurt\"," + 
    "     \"year_own\" : \"1986-1995\"" + 
    "    }," + 
    "    {" + 
    "     \"ownerid\" : \"236471\"," + 
    "     \"name\" : \"Alma\"," + 
    "     \"year_own\" : \"1999-2005\"" + 
    "    }" + 
    "   ]" + 
    "}";
    // parsing the JSON string to CardDetail object
     CarDetail detail=new Gson().fromJson(json,CarDetail.class);
    
     // retrieving data from the CardDetail object
     List<Photo> photos = detail.getPhotos();
     System.out.println("retrieving Photos");
     for (Photo photo : photos) {
        System.out.println(photo);
    }
    
     List<Info> info = detail.getInfo();
     System.out.println("retrieving Info");
     for (Info info2 : info) {
        System.out.println(info2);
    }
     System.out.println("retrieving Owners");
     List<Owner> owners = detail.getOwners();
     for (Owner owner : owners) {
        System.out.println(owner);
    }
    

    now use the retrieved data in your views. if you need any assistance/help, please let me know

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope to get solution to this problem. I have been stuck on it since
so i have been stuck with this issue for 3 weeks now and i
I'm stuck in this problem for quite while now. I have two tables ItemMaster
This has been a hard problem to diagnose and I was hoping someone could
I have been stuck on this for a while now and I cannot seem
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this for a while. i have tried and I
I have been stuck on this and don't really know how to go about
I have been stuck on this silly if statement, whatever i do, I cannot
I have now been stuck at this for some time so I though to

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.