Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Whoops, just noticed this one. I'll paste my edited answer into here:</p> <p>Okay, just for kicks, I threw this together. It compiles and functions correctly, see if you can adapt it for your particular needs:</p> <p><strong>layout/taxi_list_item.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="100dp" android:padding="10dp" android:orientation="vertical" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/taxi_name" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/taxi_address" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>layout/main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p><strong>TaxiMain.java</strong></p> <pre><code>package com.test.taxi; import java.util.ArrayList; import java.util.List; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class TaxiMain extends ListActivity { /** Called when the activity is first created. * @return */ class Taxi { private String taxiName; private String taxiAddress; public String getName() { return taxiName; } public void setName(String name) { taxiName = name; } public String getAddress() { return taxiAddress; } public void setAddress(String address) { taxiAddress = address; } public Taxi(String name, String address) { taxiName = name; taxiAddress = address; } } public class TaxiAdapter extends ArrayAdapter&lt;Taxi&gt; { private ArrayList&lt;Taxi&gt; items; private TaxiViewHolder taxiHolder; private class TaxiViewHolder { TextView name; TextView address; } public TaxiAdapter(Context context, int tvResId, ArrayList&lt;Taxi&gt; items) { super(context, tvResId, items); this.items = items; } @Override public View getView(int pos, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.taxi_list_item, null); taxiHolder = new TaxiViewHolder(); taxiHolder.name = (TextView)v.findViewById(R.id.taxi_name); taxiHolder.address = (TextView)v.findViewById(R.id.taxi_address); v.setTag(taxiHolder); } else taxiHolder = (TaxiViewHolder)v.getTag(); Taxi taxi = items.get(pos); if (taxi != null) { taxiHolder.name.setText(taxi.getName()); taxiHolder.address.setText(taxi.getAddress()); } return v; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] taxiNames = getResources().getStringArray(R.array.taxi_name_array); String[] taxiAddresses = getResources().getStringArray(R.array.taxi_address_array); ArrayList&lt;Taxi&gt; taxiList = new ArrayList&lt;Taxi&gt;(); for (int i = 0; i &lt; taxiNames.length; i++) { taxiList.add(new Taxi(taxiNames[i], taxiAddresses[i])); } setListAdapter(new TaxiAdapter(this, R.layout.taxi_list_item, taxiList)); } } </code></pre>
    singulars
    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.
    3. 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