Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not sure what the exact problem is in your code but I have a feeling it has to do with your adapter. I have suggestion on a way to do it that should work and that is better and more flexible which is basically creating your own adapter.</p> <p>First make a small Driver class which will be used as the source of data</p> <pre><code>public class DriverItem { private String name; private String driversFor; public DriverItem(String n, String d) { super(); this.name = n; this.driversFor = d; } // Getter and setter methods for all the fields. public String getName() { return name; } public String getDriversFor() { return driversFor; } </code></pre> <p>}</p> <p><strong>Now create the adapter which will be used for creating the views</strong></p> <pre><code>public class DriverListItemAdapter extends BaseAdapter { private List&lt;DriverItem&gt; listDriverItem; private Context context; public DriverListItemAdapter(Context ctx, List&lt;DriverItem&gt; list) { context = ctx; listDriverItem = list; } public int getCount() { // TODO Auto-generated method stub listDriverItem.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return listDriverItem.get(position); } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup viewGroup) { // TODO Auto-generated method stub DriverItem driver = listDriverItem.get(position); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.list, null); TextView name = (TextView)convertView.findViewById(R.id.txtName); name.setText(driver.getName()); return convertView } } </code></pre> <p><strong>Now you need the view which will be used to display each listview row</strong></p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/txtName" android:layout_height="wrap_parent" android:layout_width="fill_parent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>And now in your code you simply create the arraylist of drivers, create an adapter out of that, and set that adapter on your listview.</strong></p> <pre><code>DriverListItemAdapter adapter; ListView currentList = (ListView) findViewById(R.id.list); ArrayList&lt;DriverItem&gt; listOfDriverListItem; for(int i = 0; i &lt; jArray.length(); i++){ jObj = jArray.getJSONObject(i); listOfDriverListItem.add(newDriverItem(jObj.getString("Driver_full_name"),jObj.getString("Drives_for"))); } adapter = new DriverListItemAdapter(this, listOfDriverListItem); currentList.setAdapter(adapter); </code></pre> <p>You should be able to just copy paste the all of these things into their own classes and it should work.. and replace your listview code with the one I gave at the bottom.. This should work, let me know if you have any questions</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload