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

  • Home
  • SEARCH
  • 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 7516999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:18:32+00:00 2026-05-30T01:18:32+00:00

I searched stackoverflow but couldnt find a answer(sure there is one somewhere) but I

  • 0

I searched stackoverflow but couldnt find a answer(sure there is one somewhere) but I am trying to add a activity for each listview input. I can manage it with one intent but how do I give each listview input a seperate activity. So to be clear, I want to make every item have a serperate activity.

Currently use this code to initiate a activity but want individual activities for each item.

public class ListviewActivityActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // storing string resources into Array
    String[] adobe_products = getResources().getStringArray(R.array.list_products);

    // Binding resources Array to ListAdapter
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));

    ListView lv = getListView();

    // listening to single list item on click
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {

          // selected item
          String product = ((TextView) view).getText().toString();

          // Launching new Activity on selecting single List Item
          Intent i = new Intent(getApplicationContext(), BMICalculatorActivity.class);
          startActivity(i);


      }
    });
}

Have tried adding this but it failed to work

private static final int ACTIVITY_0 = 0;
          private static final int ACTIVITY_1 = 1;
          private static final int ACTIVITY_2 = 2;


          protected void onListItemClick(ListView l, View v, int position, long id)
          {
              super.onListItemClick(l, v, position, id);
              final Intent intent = new Intent();
              // Set up different intents based on the item clicked: 
              switch (position)
              {
                  case ACTIVITY_0:
                      intent.setClass(this, listview.activty.BMICalculatorActivity.class);
                      break;
                  case ACTIVITY_1:
                      intent.setClass(this, listview.activty.BodyLog.class);
                      break;

I know its probally simple to sort so any help would be amazing. 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-30T01:18:33+00:00Added an answer on May 30, 2026 at 1:18 am

    I think you want something like this :

         Intent i = null;
         switch (position)
              {
                  case ACTIVITY_0:
                      i = new Intent(getApplicationContext(), BMICalculatorActivity.class);
                      break;
                  case ACTIVITY_1:
                      i = new Intent(getApplicationContext(), BodyLog.class);
                      break;
              }
    
          if(i != null)
          {
             startActivity(i);
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched StackOverflow but couldn't find the answer to this question. Suppose I have
I searched StackOverflow before posting this question but I wasn't able to find the
I have searched around Google and StackOverflow trying to find a solution to this,
I've searched all forums recently including StackOverflow, but couldn't find any solution how to
I searched in google and stackoverflow for my problem, but couldn't find a good
I have searched quite extensively throught stackoverflow but unfortunately found no conclusive answer to
I searched the Eclipse settings, the web and StackOverflow, but I couldn't find an
Here is my question, and I have searched this stackoverflow but cannot find the
Ok, I searched the internet and stackoverflow but I just can't seem to find
I've searched the web and I've searched the questions here on stackoverflow, but I

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.