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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:37:48+00:00 2026-06-08T06:37:48+00:00

What i did so far is a list view of textviews having the normal

  • 0

What i did so far is a list view of textviews having the normal text and clickable spans:
Item untouched

Clicking the span i’m opening the URL, clicking the item View around the textView leads to the listView OnItemClickListener navigating to the item details, that’s fine:
Item touched outside the textView

Now the problem is:

Item textView normal text touched
Item textView span touched
touching the textView makes the normal text be kinda highlighted (with the same color it has when the item is selected completely), textView’s OnTouchListener touch event fires but not OnFocusChangeListener event and the item’s View does not get the selection style. Tried all the variations of FOCUS_BLOCK_DESCENDANTS for listView, item View, the textView focusable was enabled or disabled with the same result.

Fortunately, textView OnClickListener event fires this way, but that’s so ugly: the text is invisible while the touch is not released as the selected text color is the same as the item color, there’s no other indication that the user is going to the item details other than that ugly text vanishing.

I suspect that happens because the content of the textView is Spannable, and the parts which are not CliclableSpan-s behave in this strange way.

Any chance i could select the item once the normal text is touched ?


The listView item layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="blocksDescendants"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:focusable="false" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:focusable="false"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/info"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:focusable="false"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/details"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:focusable="false"
            android:gravity="fill_horizontal|right"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceMedium"/>

    </LinearLayout>

</LinearLayout>

With the text view setClickable(false) i’m able to disable this weird selection style in the way that nothing happens while touching the text view area, not good but might be useful for solution.

Also tried to add not focusable & not clickable button to each item, when it’s touched the complete item is selected and when touch is released the item’s click event is passed, that’s exactly what i expected from the textView with Spannable content.

  • 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-08T06:37:49+00:00Added an answer on June 8, 2026 at 6:37 am

    Did you try setting the background of your TextView to Android’s default list_selector_background?

        textView.setMovementMethod(LinkMovementMethod.getInstance());
        textView.setBackgroundResource(android.R.drawable.list_selector_background);
    

    For me it seems to give the result that you want.

    UPDATE: After seeing that the item is not just a single TextView

    Well, this is not a perfect solution (since it’s probably better to fix the TextView – ListView highlighting interaction somehow), but it works well enough.

    I figured out that instead of setting the movement method on the TextView (that triggers the issue), it is just simpler to check in the ListView’s onItemClick() (after a click is definitely confirmed) to see if we should launch the onClick() on our ClickableSpans:

    public class MyActivity extends Activity {
    
        private final Rect mLastTouch = new Rect();
    
        private boolean spanClicked(ListView list, View view, int textViewId) {
            final TextView widget = (TextView) view.findViewById(textViewId);
            list.offsetRectIntoDescendantCoords(widget, mLastTouch);
            int x = mLastTouch.right;
            int y = mLastTouch.bottom;
    
            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();
            x += widget.getScrollX();
            y += widget.getScrollY();
    
            final Layout layout = widget.getLayout();
            final int line = layout.getLineForVertical(y);
            final int off = layout.getOffsetForHorizontal(line, x);
    
            final Editable buffer = widget.getEditableText();
            final ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
    
            if (link.length == 0) return false;
    
            link[0].onClick(widget);
            return true;
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // ...
    
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (spanClicked(listView, view, R.id.details)) return;
    
                    // no span is clicked, normal onItemClick handling code here ..                    
                }
            });
            listView.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        mLastTouch.right = (int) event.getX();
                        mLastTouch.bottom = (int) event.getY();
                    }
                    return false;
                }
            });
    
            // ...
        }
    
    }
    

    The spanClicked() method is basically an abbreviated version of the LinkMovementMethod’s onTouchEvent() method in the framework. To capture the last MotionEvent coordinates (to check for the click event), we simply add an OnTouchListener on our ListView.

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

Sidebar

Related Questions

I want to output a list of news headlines that are clickable. So far
I am having a view to display a list of Shops within a UITableView.
I've done this before once, I'm trying to replicate what I did so far
I'm building an asp.net MVC 2 app. I have a list view which lists
I'm trying to write a basic, singly-linked list class in C++. I did it
So I have a custom ListView object. The list items have two textviews stacked
I have a list view full of items that contain multiple widgets each such
I'm trying to read text off the listview of another process. So far I
I have a UITableView with a list of items, each having it's own image.
I'm trying to add text labels next to my overlay images. So far the

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.