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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:30:54+00:00 2026-06-17T09:30:54+00:00

I want my ListView to highlight the selected item until selection changes. Also, I

  • 0

I want my ListView to highlight the selected item until selection changes. Also, I want to be notified when selection changes.

In order to accomplish the first task, I call list.setChoiceMode(ListView.CHOICE_MODE_SINGLE).

I’m not sure how to accomplish the second. When a list item is clicked, my OnItemSelectedListener is never notified, and the OnItemClickListener is insufficient because by the time the OnItemClick event occurs, my ListView’s checkedItem has been modified, so I cannot distinguish if the click event resulted in a selection change (it is possible/likely that the clicked item was already selected).

One option would be to store the currently checked index in a member variable, which I could use to determine if the click event corresponds to a selection change. But this ugly and
So, for this choice mode, certainly there is a way to do this with the provided listeners?

public class Temp extends Activity implements OnItemClickListener, OnItemSelectedListener
{
    ListView mView;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        List<String> strings = new ArrayList<String>();
        strings.add("1");
        strings.add("2");
        strings.add("3");
        strings.add("4");
        strings.add("5");


        mView = new ListView(this);
        mView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        mView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, strings));
        mView.setItemChecked(0, true);

        mView.setOnItemClickListener(this);
        mView.setOnItemSelectedListener(this);

        setContentView(mView);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
    {
        //this never gets called
        Log.e("item selected", ""+position);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent)
    {
        Log.e("nothing seleted", "");
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
                //by the time this occurs, position == mView.getCheckedItemPosition()
        Log.e("item clicked", ""+position);
    }
}
  • 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-17T09:30:54+00:00Added an answer on June 17, 2026 at 9:30 am

    When a list item is clicked, my OnItemSelectedListener is never notified.

    The OnItemSelectedListener is only called by a ListView when you use a trackball, keyboard navigation, or use another type of non-touch navigation. It does not correlate to the choice mode.

    One option would be to store the currently checked index in a member variable, which I could use to determine if the click event corresponds to a selection change.

    This is the best option. It only involves one extra int and an if-statement.

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

Sidebar

Related Questions

if I click on a listview item i want to keep the highlight on
I want to position custom listview item listView.setSelection(itemIndex); Selected item positioning on the top
I want to scroll listview.But Listview only scrolls when item of listview exceeded the
I want to make a listview with item name in one column and edit
I want to disable the orange highlight that occurs when touching a listView row.
Well I want to highlight the view so the user can see which item
I have a ListView and a search_term. I want to highlight (by coloring red)
I want to enable the orange highlight that occurs when touching a listView row.
I want each even item in the ListView to be of different color. For
I want my cells in my ListView to highlight on touch (just like they

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.