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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:49:31+00:00 2026-06-12T21:49:31+00:00

In my application I have a left pane that contains a list view. The

  • 0

In my application I have a left pane that contains a list view. The selection made in this list view, then calls for the relevant data, which updates the right pane, and other links and elements in the activity. Because of this design, the left pane must always have a selection made in order to give the rest of the activity useful values.

In the onCreate method of my activity I call the following in order to select the first element in the list by default. (programList is my listview)

programList.performItemClick(programList, 0, programList.getItemIdAtPosition(0);

That all works great and the view loads as expected with the right values, except for one thing.

I have added a drawable selector for the listview which highlights the selected element. When the item is physically clicked in the emulator it will highlight (I am using CHOICE_MODE_SINGLE), but it does not highlight upon calling performItemClick(). I’ve looked around for help on stackoverflow and tried to use the following before the click, but it did not make a difference.

    programList.requestFocusFromTouch();
    programList.setSelection(0);

From reading the API it sounds like the setSelection method does not set the state of the item under a touch interface, and from my results it seems that the performItemClick method does not either. I also tried to use

    programList.getAdapter().getView(0, null, null).setSelected(true);

Then I can read the state of the text view and see that it is selected, but that also did nothing to change what is displayed on the screen.

Is there something in the onCreateMethod that is preventing the state of the button from being drawn differently? I tried invalidating the drawable inside the individual text view and invalidating the text view itself, but that did not help. I also tried changing the background of the text view, but it appears that the selector that I’ve set governs that or is drawn in front. I know that I have the correct textView because I’ve used getText to read what’s inside.

If anyone is able to help me with this problem or point me towards a solution, it would be greatly appreciated.

  • 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-12T21:49:32+00:00Added an answer on June 12, 2026 at 9:49 pm

    The trick is to override the getView() method of the adapter. Try this:

    @Override
    public View getView(int position, View convertView, ViewGroup parent ) {
        final View renderer = super.getView(position, convertView, parent);
        if (position == index_of_selected_item) {
            renderer.setBackgroundResource(android.R.color.darker_gray);
        }
        return renderer;
    }
    

    Of course, you can set the background color to whatever color you like to indicate that it’s the “active” item.

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

Sidebar

Related Questions

In my application I have a dual-pane layout with a list on the left
I have an application that builds a left menu that is based on a
I have an iPad SplitViewController application in which I hide the left pane in
I have created a list view which contains a list of images defined by
I have an application that calls a web service... I get an error that
In my console application have an abstract Factory class Listener which contains code for
In My application have time consuming process.There fore i try to do that operation
I have a WPF4 application i have 1 window which editing data : main
I have application where i have two view controllers my first view and second
I have an application that i am working on which needs actually a file

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.