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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:52:00+00:00 2026-06-01T15:52:00+00:00

i’m trying to add a contextual action mode to a listview, but i’m having

  • 0

i’m trying to add a contextual action mode to a listview, but i’m having some problems with the selection, if i make aList1.setSelection(position) it doesn’t select anything, and if i make List1.setItemChecked(position, true) it works but it only changes the font color a little and i want it to change the background or something more notable, is there any way to detect the selection and manually and change the background, or i’m missing something?

the list:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ListView
         android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
      android:drawSelectorOnTop="false">
    </ListView>
</RelativeLayout>

the adapter:

public class ServicesRowAdapter extends ArrayAdapter<String[]> {
    private final Activity context;
    private final ArrayList<String[]> names;
    static class ViewHolder {
        public TextView Id;
        public TextView Date;
        public RelativeLayout statusbar,bglayout;
    }

    public ServicesRowAdapter(Activity context, ArrayList<String[]> names) {
        super(context, R.layout.servicesrowlayout, names);
        this.context = context;
        this.names = names;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        if (rowView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.servicesrowlayout, null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.Id = (TextView) rowView.findViewById(R.id.idlabel);
            viewHolder.Date = (TextView) rowView.findViewById(R.id.datelabel);
            rowView.setTag(viewHolder);
        }

        ViewHolder holder = (ViewHolder) rowView.getTag();

        holder.Date.setText(names.get(position)[2]);
        holder.Id.setText(names.get(position)[1]);
        return rowView;
    }

}

with the use of a layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <TextView
        android:id="@+id/idlabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="right"
        android:text="@+id/idlabel"
        android:textSize="20dp"
        android:width="70dp" >

    </TextView>
        <TextView
        android:id="@+id/datelabel"
        android:layout_centerVertical="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/datelabel"
        android:textSize="20dp"
        android:layout_marginLeft="90dp" >
    </TextView>

</RelativeLayout
  • 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-01T15:52:02+00:00Added an answer on June 1, 2026 at 3:52 pm

    This is becasue in touch mode there is no focused or selection. You’re on the right track using the checked state. You just need to use a state drawable with different states.

    Steps:

    1) In your row_layout.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/item_selector"
    > 
    

    2) Create a new xml file (match the name to the one you used in your row layout) in your drawable folder like so (note that I have a color.xml file set up so I can use @color/color, if you don’t you can simply put a hex color code in there):

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

    That’s it. It’s not reaql intuitive, but “activated” basically means “checked” when you have enabled the checked state.

    With that setup (and enabling the list rows to be checkable) you will now have the background changed from whatever it is normally to blue when in the checked state. Add code to set that state in onTouch or onClick and you’ll be all set. The background will stay that way until you touch another item.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.