Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3626730
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:47:57+00:00 2026-05-18T23:47:57+00:00

I am having some problems with an alertdialog box. I have a listview containing

  • 0

I am having some problems with an alertdialog box. I have a listview containing some strings and when i click the box, it shows an alert dialog box giving the option to book or cancel (its a taxi app). I am trying to get it so the name of the item chosen shows in the alert dialog box. But everytime i try it comes up showing random letters and numbers. Ill post my code as it might make it easier to understand:

Code below –

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<Taxi> {
    private ArrayList<Taxi> items;
    private TaxiViewHolder taxiHolder;

    private class TaxiViewHolder {
        TextView name;
        TextView address; 
    }

    public TaxiAdapter(Context context, int tvResId, ArrayList<Taxi> 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);

    final String[] taxiNames = getResources().getStringArray(R.array.taxi_name_array);
    final String[] taxiAddresses = getResources().getStringArray(R.array.taxi_address_array);

    ArrayList<Taxi> taxiList = new ArrayList<Taxi>();

    for (int i = 0; i < taxiNames.length; i++) {
        taxiList.add(new Taxi(taxiNames[i], taxiAddresses[i]));
    }

    setListAdapter(new TaxiAdapter(this, R.layout.taxi_list_item, taxiList));  

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> a, View v, final int position, long id)
        {   

            final int selectedPosition = position;
            AlertDialog.Builder adb=new AlertDialog.Builder(TaxiMain.this); 
             adb.setTitle("Taxi Booking");
             adb.setMessage("You Have Selected: "+taxiNames); 
             adb.setPositiveButton("Book", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     Intent intent = new Intent(TaxiMain.this, Booking.class);
                     intent.putExtra("booking",  taxiNames[selectedPosition]);
                     intent.putExtra("address",  taxiAddresses[selectedPosition]);
                     startActivity(intent);
                 }
             });
             adb.setNegativeButton("Cancel", null); 
             adb.show();
         }
     });

You’ll see at the bottom of the code, theres the line that wont work properly. –

adb.setMessage("You Have Selected: "+taxiNames);

If anyone can help into seeing why this wont show would be of great help.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:47:58+00:00Added an answer on May 18, 2026 at 11:47 pm

    When you type +taxiNames you’re performing taxiNames.toString(). taxiNames is an array containing a number of items. You need to just change it to + taxiNames[position]. Or, to keep it in line with your other Taxi objects, you could also use + taxiList.get(position).getName().

    EDIT: Out of curiosity, why are you setting another final int for selectedPosition? You already have the final int position passed in on the method call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problems trying to get my PHP running. When I
Having some problems with the jQuery UI Dialog and using checkbox values within it.
Im having some problems with binding in wpf/xaml. Have this simple file: <Window x:Class=test.Window1
After having some problems with these two linker errors on SO , I have
im having some problems with jagged arrays stored in session for ASP.net i have
I having some problems implementing IOC using windsor. I have several different implementations of
I have been having some problems with some variables inside a class being deleted
Having some problems installing BlogEngine.NET onto my CentOS mod_mono 2.8 (mono 2.8.1) box. The
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I'm having some problems with the ranking used by fulltext search in SQL Server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.