Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Subitem to a listview in Android
    primarykey
    data
    text
    <p>I currently have a listview which contains a couple of strings. These are called from a string array in strings.xml</p> <pre><code>&lt;string name="app_name"&gt;Taxi Me&lt;/string&gt; &lt;string-array name="taxi_array"&gt; &lt;item&gt;Barrys Taxi&lt;/item&gt; &lt;item&gt;Boom Taxi&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>What I was trying to do is create subitems for these so that i can show fields such as address and contact details etc. I made a customlistview a while back but cant work out how I can do it using the strings.xml file? Are there any particular tags I need to use so they show up in the list view?</p> <p>Main Activity Code: </p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String[] taxi = getResources().getStringArray(R.array.taxi_array); final String[] address = getResources().getStringArray(R.array.taxi_add); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.listtaxi, taxi)); final ListView lv = getListView(); lv.setTextFilterEnabled(true); for (int i = 0; i &lt; taxi.length; i++) { lv.add(new ListTaxi (taxi[i], address[i])); } /*lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_LONG).show(); } }); */ lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; a, View v, final int position, long id) { final int selectedPosition = position; AlertDialog.Builder adb=new AlertDialog.Builder(ListTaxi.this); adb.setTitle("Taxi Booking"); adb.setMessage("You Have Selected: "+lv.getItemAtPosition(position)); adb.setPositiveButton("Book", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(getApplicationContext(), Booking.class); intent.putExtra("booking", taxi[selectedPosition]); startActivity(intent); } }); adb.setNegativeButton("Cancel", null); adb.show(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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