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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:36:12+00:00 2026-06-07T13:36:12+00:00

I’ve been struggling with this for quite some time now, although I am pretty

  • 0

I’ve been struggling with this for quite some time now, although I am pretty sure this problem has been solved a thousand times over. I have looked at various other similar questions on SO and elsewhere but I haven’t been able to solve this.

The core issue is:

When I have clickable components in my list items, if I long-click on a row (for displaying the contextual action bar), the selector for the row does not appear. The long click is triggered though – there just isn’t any visual feedback that the long click is happening.

Note that this problem is seen only when the row layout contains clickable items. Here is a quick sort of checklist of the things I’ve already tried:

  • On the ‘ListView’, I’ve set drawSelectorOnTop to true (tried this both in XML as well as with getListView()
  • On the ‘ListView’, I’ve set choiceMode to singleChoice (tried this both in XML as well as with getListView()
  • On the ‘ListView’, I’ve set listSelector to various values – transparent, white etc. (tried this both in XML as well as with getListView().
  • Of course, the LinearLayout which hosts the individual rows in the list has longClickable set to true. Without this, the long clicks are not even registered.

No matter what I do, the long-press on the list item doesn’t display any sort of selector although the long-press did happen and I do receive the OnItemLongClick callback.

Any clues on what could be causing this?


Code to reproduce the problem:

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
android:longClickable="true"
android:orientation="horizontal" >

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/btnGo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:background="@android:drawable/btn_star_big_on" />

</LinearLayout>

activity_main.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/configurations" >
</ListView>

</LinearLayout>

MainActivity.java

public class MainActivity extends ListActivity {

private ListView mListView;
private Context mContext;
private RowAdapter mAdapter;
private static final String LOG_TAG = "ListViewLongClick";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    mListView = getListView();
    mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mListView.setSelector(android.R.color.white);
    mListView.setDrawSelectorOnTop(true);
    mAdapter = new RowAdapter(mContext, R.layout.list_item, R.id.tvTitle,
            getResources().getStringArray(R.array.configurations));
    mListView.setAdapter(mAdapter);
    mListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) {

            Toast.makeText(mContext, "Long-click on item " + position,
                    Toast.LENGTH_SHORT).show();
            return true;
        }
    });
}

static class RowAdapter extends ArrayAdapter<String> {

    private int mResource;
    private String[] configs;

    public RowAdapter(Context context, int resource,
            int textViewResourceId, String[] objects) {
        super(context, resource, textViewResourceId, objects);
        this.mResource = resource;
        this.configs = objects;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View viewToReturn = convertView;
        if (convertView == null) {
            viewToReturn = LayoutInflater.from(getContext()).inflate(
                    this.mResource, null, false);
        }

        TextView label = (TextView) viewToReturn.findViewById(R.id.tvTitle);
        label.setText(configs[position]);
        Button btn = (Button) viewToReturn.findViewById(R.id.btnGo);
        btn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Log.d(LOG_TAG, "Aha! You clicked on the star button");
            }
        });
        return viewToReturn;
    }

}

}

strings.xml

<resources>

<string name="app_name">ListViewLongClick</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>

 <string-array name="configurations">
    <item >Phone-Port</item>
    <item >Phone-Land</item>
    <item >Tab7-Port</item>
    <item >Tab7-Land</item>
    <item >Tab10-Port</item>
    <item >Tab10-Land</item>
</string-array>
</resources>
  • 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-07T13:36:13+00:00Added an answer on June 7, 2026 at 1:36 pm

    You should change your list_items like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:baselineAligned="true"
                  android:longClickable="true"
                  android:orientation="horizontal"
                  android:background="@android:drawable/list_selector_background"
            >
    
        <TextView
                android:id="@+id/tvTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <Button
                android:id="@+id/btnGo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:background="@android:drawable/btn_star_big_on" />
    
    </LinearLayout>
    

    I added android:background="@android:drawable/list_selector_background" in your LinearLayout.

    Hope this helps you =)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
Basically, what I'm trying to create is a page of div tags, each has

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.