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

The Archive Base Latest Questions

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

I have been struggling for days trying to find the proper way to implement

  • 0

I have been struggling for days trying to find the proper way to implement an action listener to a ListView. What I really want to accomplish is to create a ListView and whenever the user clicks any item, the previous Activity will be switched. I am really new at this so please help me, I would really appreciate it a lot. If you can tell me the what I’m doing wrong on my code that would be awesome!

I am using Fedor’s code from [here][1].

        ///Here I tried to Implement an action listener but It doesn't work.

        list.setOnItemClickListener(new OnItemClickListener() {                                                                                                                                                             
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id)                               
            {                                                                                                                                                                           
                if(list.getItemAtPosition(position).equals(mStrings[1]))                                                       
                {                                                                                                           
                    Intent i = new Intent(MainActivity.this, Activity2.class);                                                                                        
                    startActivity(i);                                                                                
                    }                                                                                                    
                }                                                                                                       
            });


      }
  • 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-20T23:09:57+00:00Added an answer on May 20, 2026 at 11:09 pm

    You need to override onListItemClick in such a case. Refer to
    Click Listener on ListView
    for more help, the solution is a fairly good implementation.

    Here is a possible implementation that should go in your Main activity. Please keep in mind that this will only work as long as you keep MainActivity extending Activity.

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
         // Intent launcher here
    }
    

    If you wish to extend ListActivity instead of Activity later on and you need to call to onListItemClick, do it following this scheme

    public class YourClass extends ListActivity implements OnItemClickListener{

    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
        setContentView(R.layout.your_layout);
    
        getListView().setOnItemClickListener(this);
    }
    
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // your stuff here
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling for a few days trying to find out how come
I have been struggling for 4 days trying to implement a hash algorithm in
So I have been struggling for days now, trying to simply create a new
I have been struggling for days trying to get a simple ActiveX DLL to
I have been struggling with this issue for some days now and I really
I have been struggling with a problem in the past few days. I really
sorry to post this but have been struggling now for 8 days and really
So I've been struggling with this for a couple days now. I have a
I have been struggling all afternoon trying to get a simple mailto: tag to
We have been struggling with this for a few days and have done lots

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.