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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:21:46+00:00 2026-06-12T23:21:46+00:00

This has been asked before but without an answer that works for me (and

  • 0

This has been asked before but without an answer that works for me (and apparently one other given the comment on the accepted/only answer).

I have a ListView and I’ve implemented a long-press-to-copy for each item in the list. I’m filling in the list with my own adapter that sets the OnLongClickListener and it’s functioning fine except that when I touch and hold on an item, it doesn’t highlight at all and doesn’t fade. I haven’t set any events on the ListView and no other events on the View I return from my Adapter.

I’ve read about several fixes like not using wrap_content, setting clickable to false or removing it entirely from XML. Nothing has had an impact. I have noticed that if I remove my Long Click Listener that it will animate a click, but not a fading long click.

What can I do to preserve the long click fading animation on my ListView items?

FYI: the app is targeting Gingerbread (2.3.3)

EDIT:

I’m writing a simple hash calculator. It has one activity as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:id="@+id/Input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:inputType="text">
        <requestFocus/>
    </EditText>
    <Button
        android:id="@+id/Hash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Input"
        android:onClick="StartHashes"
        android:text="@string/HashButtonText"/>
    <ListView
        android:id="@+id/HashList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Hash">
    </ListView>
</RelativeLayout>

Relevant code from my onCreate method:

    Adapter = new HashEntryAdapter(this, Entries);// Entries is Vector<HashEntry>
    ListView list = (ListView)findViewById(R.id.HashList);
    list.setAdapter(Adapter);

HashEntry is simply a class containing 2 strings: the name of the hash and the resulting output of the hash called Name and Value respectively. The HashEntryAdapter is as follows:

public class HashEntryAdapter extends ArrayAdapter<HashEntry> {

    private Context context;

    public HashEntryAdapter(Context context, List<HashEntry> objects) {
        super(context, R.layout.hashitem, objects);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //data from your adapter
        HashEntry entry = getItem(position);
        //we want to reuse already constructed row views...
        if(convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.hashitem, null);
            convertView.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    HashEntry entry = (HashEntry)v.getTag();
                    ClipboardManager clipboard = (ClipboardManager)v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(entry.Value);
                    Toast.makeText(context, entry.Name + " copied to clipboard", Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
        }
        convertView.setTag(entry);

        TextView Name = (TextView)convertView.findViewById(R.id.HashName);
        TextView Value = (TextView)convertView.findViewById(R.id.HashValue);

        Name.setText(entry.Name);
        Value.setText(entry.Value);

        return convertView;
    }
}

And finally, hashitem.xml, a simple layout to put a grayed hash name over a black hash value:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/HashName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/HashNameFiller"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/DarkGray"/>
    <TextView
        android:id="@+id/HashValue"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/HashName"
        android:layout_centerHorizontal="true"
        android:text="@string/HashValueFiller"
        android:textAppearance="?android:attr/textAppearanceMedium"/>
</RelativeLayout>

OnCreateContextMenu for vikki:

    list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        }
    });
  • 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-12T23:21:48+00:00Added an answer on June 12, 2026 at 11:21 pm

    You could just use onCreateContextMenu like the stock messaging app does in ICS when you want to delete a conversation thread. You can get the id and position just like in onLongClickListener if you cast ContextMenuInfo to AdapterContextMenuInfo

    import android.widget.AdapterView.AdapterContextMenuInfo
    
    ...
    
    list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            AdapterContextMenuInfo contextInfo = (AdapterContextMenuInfo) menuInfo;
            int position = contextInfo.position;
            long id = contextInfo.id;
            // the child view who's info we're viewing (should be equal to v)
            View view = contextInfo.targetView;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It has been asked before, but without a full answer . This is to
Apologies if this has been asked before (I couldn't find the answer anywhere), but
This has been asked before but I can't find a definitive answer, in code.
I know that this has been asked a million times before, but nothing that
I know this has been asked before but I have looked at every answer
I understand that this question has been asked before, but most of the time
This question has been asked before but 1) the user never accepted an answer
This question has been asked before, but I can't find any answers that have
This has been asked once before but that didn't work for me at all.
This has been asked before but I cannot find the answer I need. 1)

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.