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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:19:34+00:00 2026-06-05T21:19:34+00:00

I am working on an android app, and I am having difficulties with ListActivity

  • 0

I am working on an android app, and I am having difficulties with ListActivity. I would like to have a different Activity start depending on which item in the list is clicked.

I made a list and referenced it with setListAdapter in java, but I am not sure how to reference in the OnListItemClick. I assume I need to reference the position in the list.

With Activity and Buttons, I can set the OnClickListener and use a switch statement with a case for each Button. What is the equivalent for ListActivity?

Here is my code:

public class Options extends ListActivity implements {

    String myHistory[]= { "Item 1", "Item 2", "Item 3" };

    //---Set ListView---
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String> ( Options.this,
                                   android.R.layout.simple_list_item_1, myHistory)));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id); 

        //--if click position 1, do below
        //--Intent a = new Intent("show Item 1's corresponding page");
        //--startActivity(a);

        //--if click item in position 2, do below
        //--Intent b = new Intent("show Item 2's corresponding page");
        //--startActivity(b);

        //--if click item in position 3, do below
        //--Intent c = new Intent("show Item 3's corresponding page");
        //--startActivity(c);
    }
}
  • 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-06-05T21:19:36+00:00Added an answer on June 5, 2026 at 9:19 pm

    as looks there are only few and certain data in list not at run time because each item has a separate activity (like a menu list of game) so I will suggest to go short and simple …….

        protected void onListItemClick(ListView l, View v, int position, long id) {
            // TODO Auto-generated method stub
            super.onListItemClick(l, v, position, id); 
    
            Intent a;
             switch(position){
    
            case 1:
                a = new Intent("show Item 1's corresponding page");
                break;
             case 2:
               a  = new Intent("show Item 2's corresponding page");
               break;
            case 3:
               a = new Intent("show Item 3's corresponding page");
               break;
    
            if(null!=a)
            startActivity(a);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on android app development in which how get profiling information like Data
I am currently working on an Android app and I am having some issues
I'm working on my Android app and I'm having a bit of a weird
I'm working on an Android app having an always visible tabbar. However, each tab
I am now working on an android app in which I need to display
I'm working on adding a YouTube channel to my Android App and I'm having
I've been working on a small media player app for Android. I'm having some
I'm having a problem with my android program. I have about every thing working
I'm developing an Android app which will target 2.1/2.2 devices, so I have my
I'm creating my first android app (or attempting to anyway) and i have a

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.