Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to put an <code>onClickListener</code> onto your positive button, which will launch the new activity and pass the data to it. Your code would become something like:</p> <pre><code>public class ListTaxi extends ListActivity{ /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String[] taxi = getResources().getStringArray(R.array.taxi_array); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.listtaxi, taxi)); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { final int selectedPosition = position; AlertDialog.Builder adb=new AlertDialog.Builder(ListTaxi.this); adb.setTitle("Taxi Booking"); adb.setMessage("You have chosen = "+lv.getItemAtPosition(position)); adb.setPositiveButton("Book", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(getApplicationContext(), NextActivity.class); intent.putExtra("booking", taxi[selectedPosition]; startActivity(intent); } }); adb.setNegativeButton("Cancel", null); adb.show(); } }); </code></pre> <p>In your target activity, have something like this:</p> <pre><code>Intent intent = getIntent(); String booking = ""; if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { booking = extras.getString("booking"); } } </code></pre>
 

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