0

Guys recently i switched to Retrofit from volley. there is a Pojo file which is converted from json.

public class JobModel {

    private int status;

    private List<JobsBean> jobs;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public List<JobsBean> getJobs() {
        return jobs;
    }

    public void setJobs(List<JobsBean> jobs) {
        this.jobs = jobs;
    }

    public static class JobsBean {
        private String job_city;

        public String getJob_city() {
            return job_city;
        }
    }
}

but i don't know how to use this pojo file to extract the job_city from JobsBean class

As you can see there is an JsonArray jobs which is converted to

List<JobsBean> 

having JsonObjects and the

JobsBean class

is containing all the job_city name. How can i retrieve these job_city name in an array. so that i can use them in my arrayadapter.

Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44

2 Answers2

0

Use ArrayAdapter<JobsBean> and it will take a JobsBean list as a parameter for the model data.

You will need to override getView() to read the data from the JobsBean item and put it into the list item view.

kris larson
  • 30,387
  • 5
  • 62
  • 74
0

Change the POJO structure as follow:

public class JobModel {
    private int status;
    private List<JobsBean> jobs;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public List<JobsBean> getJobs() {
        return jobs;
    }

    public void setJobs(List<JobsBean> jobs) {
        this.jobs = jobs;
    }
}

public class JobsBean {
    private String job_city;

    public String getJob_city() {
        return job_city;
    }

    public void setJob_city(String job_city) {
        this.job_city = job_city;
    }
}

The default GsonConverterFactory should be more than enough to handle this nested POJO. And you should be able to get the result like:

JobModel.getJobs().get(index).getJob_city();
Da DUAN
  • 522
  • 1
  • 5
  • 8
  • @VishalJangid, Is it able to resolve your issue? You can accept the solution and help the other people who has the same problem. – Da DUAN Jun 22 '16 at 04:12