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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:38:57+00:00 2026-05-31T18:38:57+00:00

I have a ListView which contains custom rows. This custom row has following UI

  • 0

I have a ListView which contains custom rows. This custom row has following UI elements

  1. ImageView imageView1,imageView2
  2. TextView textview1,textView2,textView3

The requirement is whenever the list row is SELECTED there would be following changes

imageView1 background,color is changed

imageView1 color is changed

textview1 color,size and typeface is changes

textview2 color,size is changed

textview3 color,size is changed

What would be the best way to design for this?

AFAIK we cannot apply styles in the selector. Is there a better way to work on this rather than handling in the java code?

We have setOnItemSelectedListener that can be set on a Listview which would have following callback methods:

i) onItemSelected

ii) onNothingSelected

However there is no callback method which provide details of the item which has lost its focus. Is this a better place to make the changes?

Thanks in advance.

  • 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-31T18:38:59+00:00Added an answer on May 31, 2026 at 6:38 pm

    I think what you want to do here is create a Compound Control. You can find an example in your SDK directory in the samples//ApiDemos subdirectory (you may want to download the Android source if you don’t have these directories).

    What I would do is create a class that inherits from whatever kind of layout you are using for your custom row. Let’s suppose it’s a LinearLayout for this example. In your subclass constructor, you can inflate your layout from a resource, find the subViews and attach them to instance variables, and return the LinearLayout to the caller.

    In this subclass, you can override setSelected and manipulate the subViews in whatever way you want.

    Here’s an example of what I am describing based on your post:

    public class MyCustomLayout extends LinearLayout {
        public ImageView imageView1;   // These are public since you likely want
        public ImageView imageView2;   // to set them in your Adapter.
        public TextView textView1;
        public TextView textView2;
        public TextView textView3;
    
        public MyCustomLayout(Context ctxt) {
            super(ctxt);
    
            // The call below attaches the items in the mycustomlayout.xml file to this
            // instance, which serves as the root element in the layout.
            LayoutInflater.from(ctxt).inflate(R.layout.mycustomlayout, this, true);
    
            imageView1 = (ImageView)findViewById(R.id.imageview1);
            imageView2 = (ImageView)findViewById(R.id.imageview2);
            textView1 = (TextView)findViewById(R.id.textview1);
            textView2 = (TextView)findViewById(R.id.textview2);
            textView3 = (TextView)findViewById(R.id.textview3);
        }
    
        @Override
        public void setSelected(boolean selected) {
            super.setChecked(selected);
            if (selected) {
                imageView1.setBackgroundColor(0xFFFF0000); // whatever color you want
                // Do all the rest of the setting of your subviews here for
                // the case when the row is selected.
            } else {
                imageView1.setBackgroundColor(0xFF000000); // whatever color you want
                // Do all the rest of the setting of your subviews here for
                // the case when the row is not selected
            }
        }
    }
    

    Now, in the mycustomlayout.xml file, you want to use the <merge> tag so that you don’t create an unneeded layout:

    <merge xmlns:android="http://schemas.android.com/apk/res/android">
        <ImageView
            android:id="@+id/imageview1" />
        <ImageView
            android:id="@+id/imageview2" />
        <TextView
            android:id="@+id/textview1" />
        <TextView
            android:id="@+id/textview2" />
        <TextView
            android:id="@+id/textview3" />
    </merge>
    

    I’ve elided all the configuration of the subviews above, obviously, but you should get the idea about how to set up the XML file. You could also do this in code if you don’t want to fool with XML and a LayoutInflater. You can look at this helpful blog post on the Android dev blog which discusses a similar case towards the end.

    Then, in your Adapter’s getView you can just create (or recycle) instances of MyCustomLayout, set them up, and let the framework take care of keeping track of which rows are selected and which aren’t selected.

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

Sidebar

Related Questions

I have one custom ListView which contains one ImageView and one TextView, and I
I have a listview which contains custom rows. When I show the listview with
I have made a custom listView which which extends ListActivity and each row contains
I have a ListView which contains an ImageView and a TextView. I'm subclassing ArrayAdapter
I have a problem with my listview which contains an ImageView and a few
This is probably easy as well. But I have this listview which contains exe
I have a ListView in which each item has a complex layout that contains,
I have a custom listview which changes size when one of the rows is
I have a ListView which uses a custom adapter to display rows of data.
I have a listview which I am populating with a custom SimpleCursorAdapter, each row

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.