How to get a specific entry from a custom ArrayList?
<p>I have an Android app that uses <code>Retrofit</code> to consume an API, puts JSON into a custom <code>ArrayList</code> and then populates a <code>ListView</code> by using a custom <code>ArrayAdapter</code>. This works as intended.</p>

<p>The <code>ListView</code> items display 3 of the 7 values available in the model I used. Now I wanted to make it so that upon clicking a list item, a new activity starts and displays a complete entry, with all the 7 values.</p>

<p>I made the list items clickable with <code>onItemClickListener</code> and made an <code>Intent</code> that starts the new Activity. This Activity has a couple of <code>TextView</code>'s that are there to house all the 7 values from a single entry. I made the JSON <code>ArrayList</code> parcelable and passed it as an Extra along with the <code>Intent</code>. </p>

<p><strong>The problem:</strong></p>

<p>I can populate <code>ListView</code>'s and <code>RecyclerView</code>'s alright, but I don't know how to extract JSON data that's under a specific index. <code>ArrayList.get(x)</code> doesn't work, because the object is custom and doesn't include that method, I think. Here's my <code>ArrayList</code> model:</p>

<pre><code>public class ListModel implements Parcelable {

@SerializedName("id")
private String idno;

@SerializedName("name")
private String name;

@SerializedName("telno")
private String telno;

@SerializedName("street")
private String street;

@SerializedName("city")
private String city;

@SerializedName("hour")
private String hour;

@SerializedName("desc")
private String desc;


public ListModel(String idno,
                 String name,
                 String telno,
                 String street,
                 String city,
                 String hour,
                 String desc) {
    this.setIdno(idno);
    this.setName(name);
    this.setTelno(telno);
    this.setStreet(street);
    this.setCity(city);
    this.setHour(hour);
    this.setDesc(desc);
}

public String getIdno() {return idno;}
public void setIdno(String idno) {this.idno = idno;}

public String getName() {return name;}
public void setName(String name) {this.name = name;}

public String getTelno() {return telno;}
public void setTelno(String telno) {this.telno = telno;}

public String getStreet() {return street;}
public void setStreet(String street) {this.street = street;}

public String getCity() {return city;}
public void setCity(String city) {this.city = city;}

public String getHour() {return hour;}
public void setHour(String hour) {this.hour = hour;}

public String getDesc() {return desc;}
public void setDesc(String desc) {this.desc = desc;}

// Parcel stuff after this
</code></pre>

<p>Also, here's a snippet of the JSON:</p>

<pre><code>[{"id":1,"name":"Young","telno":"692-(371)616-8685","street":"96333 Anhalt Court","city":"Loen","hour":"18:38","desc":"Quisque id justo sit amet sapien dignissim vestibulum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;"},
 {"id":2,"name":"Fowler","telno":"46-(368)133-6356","street":"5 School Parkway","city":"Onsala","hour":"16:17","desc":"Proin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis. Ut at dolor quis odio consequat varius."},
</code></pre>

<p>Here's the adapter:</p>

<pre><code>public class UsersAdapter extends ArrayAdapter&lt;ListModel&gt; {


public UsersAdapter(Context context, ArrayList&lt;ListModel&gt; users) {
    super(context, 0, users);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ListModel listModel = getItem(position);

    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }

    TextView hourTV = (TextView) convertView.findViewById(R.id.hourTV);
    TextView idnoTV = (TextView) convertView.findViewById(R.id.idnoTV);
    TextView nameTV = (TextView) convertView.findViewById(R.id.nameTV);

    hourTV.setText(listModel.getHour());
    idnoTV.setText(listModel.getIdno());
    nameTV.setText(listModel.getName());

    return convertView;

}
</code></pre>

<p>}</p>

<p>Please let me know if any more code is needed. This is my first app, so please bear with me if I'm missing something obvious, or don't explain myself clearly enough.</p>

<p>Thank you.</p>

<p><strong>SOLUTION EDIT</strong></p>

<p>Here's a working result:</p>

<p><code>MainActivity.java</code></p>

<pre><code>public ArrayList&lt;ListModel&gt; dataSource = new ArrayList&lt;&gt;();

// Retrofit fetches and parses JSON here.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int position, long id) {

            Intent detailViewIntent = new Intent(MainActivity.this, DetailView.class);

            ListModel listModel = dataSource.get(position);
            detailViewIntent.putExtra("TAG", listModel);
            Bundle bundle = new Bundle();
            bundle.putParcelable("jsondata", listModel);
            detailViewIntent.putExtras(bundle);
            startActivity(detailViewIntent);
        }
    });
}
</code></pre>

<p><code>DetailView.class</code></p>

<pre><code>public class DetailView extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail_view);

    Bundle bundle = getIntent().getExtras();
    ListModel jsondata = bundle.getParcelable("jsondata");

    // Populate 7 TextViews using ListModel getters like so: 
    TextView hourTV = (TextView) findViewById(R.id.hourTV);
    hourTV.setText(jsondata.getHour());
</code></pre>