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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:20:40+00:00 2026-06-09T19:20:40+00:00

I am having problems defining a ListView with a custom adapter and list item

  • 0

I am having problems defining a ListView with a custom adapter and list item xml layout. The problem is that my ListView is not highlight items when pressed. I am doing the following:

I define a drawable selector xml resource file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@android:color/holo_orange_light" />
    <item android:state_pressed="false" android:drawable="@android:color/white" />
</selector>

I define an item layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/btn_voice_item" 
     >

    <ImageButton
        android:id="@+id/voiceItemFavorite"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:background="@drawable/btn_favorite" />

    <TextView
        android:id="@+id/voiceItemText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:layout_toRightOf="@+id/voiceItemFavorite"
        android:background="@drawable/btn_voice_item" />

</RelativeLayout>

Finally I wrote code in my custom data adapter to inflate and populate then view.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.voice_item, null);
    }
    VoiceItem i = getItem(position);
    TextView t = (TextView) convertView.findViewById(R.id.voiceItemText);
    t.setText(i.toString());
    ImageButton b = (ImageButton) convertView.findViewById(R.id.voiceItemFavorite);
    b.setTag(i);
    b.setSelected(i.favorite);
    b.setOnClickListener(new FavoriteClick());
    return convertView;
}

Everything works except when I press items in the list there is no visual indication of the press. I expect the color of the pressed item’s background to transition to the style defined by my drawable selector.

How can I both have a custom view items and retain styling highlighting of items while pressed?

  • 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-09T19:20:42+00:00Added an answer on June 9, 2026 at 7:20 pm

    If android:background="@drawable/btn_voice_item" is solid image so it’ll cover the ListView selector. Here is very detail tutorial about custom ListView selector and item backround
    ListViewTipsandTricks part3 (Cyril Mottier)

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

Sidebar

Related Questions

I am having problem defining CSS rules for browsers that do not support font-stretch
im having problems starting a codeigniter project, the problem is that when i do
I'm having some problems when defining inner classes in a Test class inherited from
Having problems iterating. Problem has to do with const correctness, I think. I assume
I'm using the version 0.3.1 of Cuke4Nuke and I'm having problems defining my feature-files
Problem: I am having trouble generating an xpath expression that selects a node in
I'm having some problems with defining a binding bean for my rich:dataTable. The contents
I'm writing a custom ATL ActiveX component, but I'm having this little weeny problem:
I am having problems defining recursion in a function I have wrote. I am
I've been using custom attributes for some custom layout components without problem. So far,

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.