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 5994265
In Process

The Archive Base Latest Questions

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

I have an app in android in which I’m setting up a list view…and

  • 0

I have an app in android in which I’m setting up a list view…and now try to display a message when I press on one of the items….but it’s not working…I’m sure is something simple but I just can figure out what it is…and my listener won’t work!

public class Server3 extends ListActivity {

    static final String[] items=new String[] {"Car1",  "Car2", "Car3","Car4", "Car5"};




    public class MyCustomAdapter extends ArrayAdapter<String>{

        public MyCustomAdapter(Context context, int textViewResourceId, String[] objects) {
                 super(context, textViewResourceId, objects);
                 // TODO Auto-generated constructor stub
                }

                @Override
                public View getView (int position, View convertView, ViewGroup parent) {
                 // TODO Auto-generated method stub
                 LayoutInflater inflater=getLayoutInflater();
                 View row=inflater.inflate(R.layout.row, parent, false);
                 TextView label=(TextView)row.findViewById(R.id.item);
                 label.setText(items[position]);
                 ImageView icon=(ImageView)row.findViewById(R.id.icon);

                 if (items[position]=="Car1"){
                  icon.setImageResource(R.drawable.car1);
                 }
                 if (items[position]=="Car2"){
                      icon.setImageResource(R.drawable.car2);
                     }
                 if (items[position]=="Car3"){
                     icon.setImageResource(R.drawable.car3);             
                 }
                 if (items[position]=="Car4"){
                     icon.setImageResource(R.drawable.car4);             
                 }
                 if (items[position]=="Car5"){
                     icon.setImageResource(R.drawable.car5);             
                 }

                 return row;
                }
                }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.server3);

         setListAdapter(new MyCustomAdapter(Server3.this, R.layout.row, items));

        final ListView listView = getListView();


        listView.setItemsCanFocus(false);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 





    }

     @Override 
    /* public void onCreateContextMenu(ContextMenu menu, View v,  ContextMenuInfo menuInfo) {  

             menu.setHeaderTitle("Choose");  
             menu.add(0, MENU_track, 0, "Track");  
             menu.add(0, MENU_delete, 0,  "Delete");

     } 
    @Override
    public boolean onContextItemSelected(MenuItem item) {  

        switch (item.getItemId()) {  
            case MENU_track:  
                  Intent j1 = new Intent(Server3.this, Server4.class);
                   startActivity(j1);
                return true;  

            case MENU_delete:    
                  return true;  

            default:    
                return super.onContextItemSelected(item);  
        }
    }*/


    public void onListItemClick(ListView listView,View v,int position,long id)
    {

        if(items[position]=="car1")
        {
            Toast.makeText(this, "am apasat", 0).show();
        }
        if(items[position]=="car2")
        {
            System.out.println("am selectat masina 2");
        }

    }









}

If someone could tell mey why there is no message display when I click on it I would be gratefull.thx

  • 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-22T23:47:38+00:00Added an answer on May 22, 2026 at 11:47 pm

    in the onListItemClick you have written `if(items[position]==”car1″)

    `

    It’s Car1 . System.out in your car2 (wrong, it’s Car2) will not work.

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

Sidebar

Related Questions

I have an Android app with a ListActivity in the main view. The list
I have android app in which one layout contains Linearlayout , ScrollView , TextView
I have android app which works fine. And now I want to add some
I have an Android App which consists on different modules. The Main module is
I have an android app which needs to be signed using a specific keystore
I have written an android app which listens to the phone signal strength using
I have published an app on Android Market which is limited to Norway. I'm
I was wondering if it was possible to have an android app which is
I have an android app for which i need to ensure that it has
I have developed an Android app which I want to be available both as

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.