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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:22:55+00:00 2026-06-06T18:22:55+00:00

I have implemented a ListActivity , and would like to launch a different intent

  • 0

I have implemented a ListActivity, and would like to launch a different intent for each possible selection of the items in the list.

For example:

enter image description here

Clicking on About item should launch an intent with a new activity, and clicking on the Access Phone Gallery item should launch an intent opening the Phone Gallery (for selecting an image say).

I’d like to understand two things:

  1. How can I determine which item was clicked, so that I can launch the correct intent?
  2. How can I make the items in the list change style when they are selected? (say become highlighted so that the User Experience is better)

The following is the code of MyActivity (implementing the ListActivity):

public class MyActivity extends ListActivity implements OnItemClickListener 
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    { 

        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_activity);

        ListView listView = (ListView) findViewById(android.R.id.list);

        listEntryClass listEntries[] = new listEntryClass[]
        {
            new listEntryClass( "About", "About" ),
            new listEntryClass( "Access Phone Gallery", "Access Gallery and Choose an Image" )
        };

        listEntryArrayAdapter adapter = new listEntryArrayAdapter(this, R.layout.list_entry_layout, listEntries);

        View header = (View)getLayoutInflater().inflate(R.layout.list_header_layout, null);
        TextView headerValue = (TextView) header.findViewById(R.id.list_header);
        headerValue.setText( this.getString(R.string.headerPrefs) );

        listView.addHeaderView(header);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener( this );

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    {

        Log.d(TAG, "Clicked an entry");
    }

}

I guess there should be something like a switch-case on the id of the clicked item at some place, but have no idea of how to do it.

  • 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-06T18:22:56+00:00Added an answer on June 6, 2026 at 6:22 pm

    How can I determine which item was clicked, so that I can launch the correct intent?

       @Override
        public void onItemClick(AdapterView <? > parent, View view, int position, long id) {
    
           // Here position denotes which row index you clicked.
          //If you clicked first item in ListView then row index will be zero
         // and so on...
    
           switch (position) {
           case 0:
               //First Item/row clicked
               break;
           case 1:
               //Second Item/row clicked
               break;
           }
       }
    

    How can I make the items in the list change style when they are selected? (say become highlighted so that the User Experience is better)

    As for setting the color, you need a StateListDrawable . You can set this on your list using the android:listSelector attribute, defining the drawable in XML like this:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:state_enabled="false" android:state_focused="true"
            android:drawable="@drawable/item_disabled" />
      <item android:state_pressed="true"
            android:drawable="@drawable/item_pressed" />
      <item android:state_focused="true"
            android:drawable="@drawable/item_focused" />
    </selector>
    

    ListView xml will look like below.

    <ListView android:id="@+id/list" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" 
          android:dividerHeight="0dip"
          android:divider="@null" 
          android:listSelector="@drawable/list_selector"
          android:layout_gravity="center" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have the listview in a ListActivity be displayed with the
I have implemented a very basic sign up using email address+name, although I would
I have a ListActivity and I want to implement context menu for each of
I have a ListActivity class, and when any item on the list is clicked,
I have a ListActivity which queries a web service for data. I've implemented a
This is my ListActivity after clicking on the list it will start a new
I currently have a custom listview where each item on the list contains two
I have a ListActivity containing Items which are fetched from a JSON Object. When
I have a ListActivity with my customized adapter and inside each of the view,
I have implemented a templated buffer class like this: template <class T, class Impl>

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.