Android – ListView doesn't receive OnItemClick for textview with clickable links-ThrowExceptions

Exception or error:

I have a ListView that contains a TextView in each row besides a number of other views. The TextView renders html content which may contain links.

The below code appears in the list adapter.

This causes the listview to no longer receive on click events though. I decided to put the list onclick code on the view being returned by the adapter instead. This doesnt quite work as desired. Now I can launch another activity when I click anywhere in the row except the textview. I want users to be able to click on the non-links part of the textview and launch another activity.

If I move the onclick to the textview instead of its parent view, it works but now a click on the link fires two events – one for the click on the link and another for the textview (which is not desired).

I have noticed that google+ and peep on android work in the manner I want. I’m not sure how that can be achieved.

How to solve:

This is actually a BUG. To resolve this you can add android:descendantFocusability="blocksDescendants" you your ListView's rows layout xml. For e.g

<LinearLayout xmlns:android=""
android:orientation="vertical" >

    android:textSize="15sp" />

Source : this and this

Good Luck 🙂


Focusable views inside a ListView item will disable the ability to select ListView items. Applying android:focusable="false" to the TextView will allow OnItemClick to work again. You may also need to apply android:focusableInTouchMode="false" to make the trackball ignore the links because clicking the trackball over a focusable element in a ListView can both click the link and the ListView item.


You can attach on the list view an setOnItemClickListener.


I had the same issue and none of these answers worked for me. Eventually, I managed to fix the problem by removing the attribute android:inputType="textMultiLine".


TextView that only responds to touch events of links. Based on

        public class AutoLinkTextView extends TextView {

            public AutoLinkTextView(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);

            public AutoLinkTextView(Context context, AttributeSet attrs) {
                super(context, attrs);

            public AutoLinkTextView(Context context) {

            private void init() {

             * @Linkify applies to a movementMethod to the textView @LinkMovementMethod.
             *          That movement method thought it implements a scrolling
             *          vertically method it overrides any other scrolling method the
             *          parent has.
             *          Although touchEvent can be dispached to the parent, the specific
             *          parent ScrollView needed the whole sequence ACTION_DOWN ,
             *          ACTION_MOVE, ACTION_UP to perform (sweep detection). So the
             *          solution to this problem is after applying @Linkify we need to
             *          remove the textView's scrolling method and handle the @LinkMovementMethod
             *          link detection action in onTouchEvent of the textView.
            public boolean onTouchEvent(MotionEvent event) {
                final TextView widget = (TextView) this;
                final Object text = widget.getText();
                if (text instanceof Spannable) {
                    final Spannable buffer = (Spannable) text;
                    final int action = event.getAction();

                    if (action == MotionEvent.ACTION_UP
                            || action == MotionEvent.ACTION_DOWN) {
                        int x = (int) event.getX();
                        int y = (int) event.getY();

                        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 ClickableSpan[] link = buffer.getSpans(off, off,

                        if (link.length != 0) {
                            if (action == MotionEvent.ACTION_UP) {
                            } else if (action == MotionEvent.ACTION_DOWN) {
                            return true;

                return false;

            public void setText(CharSequence text, BufferType type) {
                super.setText(text, type);

Leave a Reply

Your email address will not be published. Required fields are marked *