Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Displaying ListView item in a textview
    primarykey
    data
    text
    <p>I have managed to setup a page so that a user clicks an item in a listview which then shows an alertdialog box and gives them the option to book or cancel. If they click book it takes them to another screen. What i need is to show the item selected on the next screen. I almost have it but i cant work out where its going wrong. What i was hoping is if someone could help in working out the best way to do this?</p> <p>My code at present is - </p> <pre><code> 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 chosen = "+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> <p>And on the booking.java is: </p> <p>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.booking); TextView tv_taxi = (TextView) findViewById(R.id.tvtaxi); //tv_taxi.setText(taxi);</p> <pre><code> Intent intent = getIntent(); String booking = ""; if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { booking = extras.getString("booking"); } } } </code></pre> <p>Original article is at - <a href="https://stackoverflow.com/questions/4584668/android-change-view-when-alertdialog-button-is-clicked">Android - Change View when alertdialog button is clicked</a></p> <p>Thanks Everyone</p>
    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. 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