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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:24:22+00:00 2026-06-17T21:24:22+00:00

So I have a listview that shows random texts. The textview may sometimes be

  • 0

So I have a listview that shows random texts. The textview may sometimes be regular text, but can also be URLs and the like. I added the following line to my BaseAdapter’s code:

Linkify.addLinks(mHolder.content, Linkify.WEB_URLS);

Where mHolder is an instance of a ViewHolder to speed the listView up, content being the TextView inside that viewHolder, and I am only willing to highlight Web Urls.

First Problem,

Since adding that line of code some of the items that only have regular text like “asdfg” are now no longer highlighted when clicked. And just to clarify, When I mean “highlighted” I only mean the regular highlight that happens when a listView item is clicked, whether or not there was code supplied to handle the onClick event.

I know the issue here is that line of code, since removing it makes all items on the listView highlight when clicked. I tried to describe this via this screenshot

Second Problem,

I added a MultiChoiceModeListener to the listView to handle ActionMode; however, given that the links inside the textViews are now clickable and will launch the browser, they are no longer functioning properly when in ActionMode, as they do not care that we are in ActionMode and still launch the browser instead of following the code inside the onItemCheckedStateChanged method.

For example, when in ActionMode, every item that the user clicks is added to an ArrayList called itemsChecked that is later used via onActionItemClicked. However, when using linkify this is no longer viable, as when the user clicks a ListView item that has a web Url as text, the app will be sent to the background as the browser is called to handle the link.

My questions is What can I do to potentially fix these issues in my code?

I want to have links highlighted and clickable, but not at this cost. Should I use something else other than Linkify to highlight links and make them clickable? Or is that “clickability” always going to interfere with the regular behavior of a ListView item.

FYI, the code that I am running for the ActionMode and ListView are the following: (Keep in mind that the code works appropriately when NOT using Linkify

private MultiChoiceModeListener modeListener = new MultiChoiceModeListener() {

     @SuppressLint("NewApi")
    @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position,
                                              long id, boolean checked) {   
            String text =  listItems.get(position);
            if (checked) {
                itemsChecked.add(text);
            }
            else {
                int index = itemsChecked.indexOf(text);
                itemsChecked.remove(index);
            }               
        }

        @SuppressLint("NewApi")
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
                case 0:
                    mode.finish();
                    return true;
                case R.id.menu_merge:
                    mergeStrings();
                    mode.finish();
                    return true;                 
                case R.id.menu_star:
                    return false;                
                default:
                    return false;
            }
        }

        @SuppressLint("NewApi")
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            inActionMode = true;
            itemsChecked = new ArrayList<String>();
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.context_menu, menu);
            return true;
        }

        @SuppressLint("NewApi")
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            inActionMode = false;
        }

        @SuppressLint("NewApi")
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }
};

@SuppressLint("NewApi")
private void initViews () {

    listView = (ListView) findViewById(R.id.home_list_view);
    if (isOldAPI) {
        registerForContextMenu(listView);
    }
    else {
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        listView.setMultiChoiceModeListener(modeListener);          
    }
    mAdapter = new MyAdapter(this, listItems, isOldAPI);                
    listView.setAdapter(mAdapter);
}
  • 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-17T21:24:24+00:00Added an answer on June 17, 2026 at 9:24 pm

    Alright, so after some time lurking in the shadows for an answer, I finally got it thanks to the AOSP MMS code. Credit goes to Rascarlo for posting on github, although i think I may also be available through CM and other projects.

    So, the problem was that I was using this line of code inside my adapter:

    Linkify.addLinks(mHolder.content, Linkify.WEB_URLS);
    

    When all that can be better address on the XML of the textview, by using the pre-built properties android:autoLink, which must be set to whatever scheme you prefer – web in my case; and android:linksClickable, which MUST be set to FALSE if you want the clicks to highlight the line item. Setting it to true will do as well, context menu via longclick works, but it just doesn’t highlight. Please note that by setting it to false, you will have to handle the opening of such links via code, and not via click.

    Here is the XML code for my ListView item:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"    
    android:orientation="horizontal" >
    
    <TextView
        android:id="@+id/clip_list_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="4dp"
        android:autoLink="web"
        android:linksClickable="false"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    

    Hope that helps those who could not figure it out.

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

Sidebar

Related Questions

I have a ListView that shows around 300 items. When something is changed and
I have a ListView that shows a list of names. When you select a
I have a ListView and DropDownList in every Row of that ListView. You can
i have a ListView that simly shows items on it. I want to load
I'm developing a RSS reader android app. I have a ListView that shows my
I have a dialog that shows a ListView of certain items like this d
I have created a dialog that shows a multi-choice list of items that can
I have ListView that shows data: <ListView android:id=@+android:id/list android:layout_width=fill_parent android:layout_height=wrap_content> </ListView> The headlines is
I have a ListView that shows a list of search results. To make things
I have a Listview that looks like the following: checkbox:textview {0 .. n} I

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.