1

I have a ListView with a custom list adapter (that extends BaseAdapter). My list items' view are inflated from this 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="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center_vertical"
        >
        <TextView
            android:id="@+id/txtOne"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
        />

        <TextView
            android:id="@+id/txtTwo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />
    </LinearLayout>
</LinearLayout>

At getView method the items' view are created and populated:

if (convertView == null) {
    convertView = inflater.inflate(R.layout.teste, parent, false);
}
((TextView) convertView.findViewById(R.id.txtOne)).setText("Some text");
final SpannableString ss = new SpannableString("Another text");
ss.setSpan(new ClickableSpan() {
    @Override
    public void onClick(final View widget) {
        startActivity(new Intent(widget.getContext(), AnotherActivity.class));
    }
    }, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
((TextView) convertView.findViewById(R.id.txtTwo)).setText(ss);

It's showing my spannable string on item's view, but I cannot touch on it. I can only touch the entire item view.

I want to start another activity when user touches on spannable string but I also want the entire item view toucheable.

What am I missing?

pmaruszczyk
  • 2,157
  • 2
  • 24
  • 49
Gabriela Vasselai
  • 222
  • 1
  • 5
  • 13

1 Answers1

3

You need to do one of two things:

  1. android:linksClickable="true" on the TextView in layout

  2. in code: txtViewTwo.setMovementMethod(LinkMovementMethod.getInstance());

The end result would be the same.

Joe
  • 42,036
  • 13
  • 45
  • 61
  • Quick question for answerer or OP if y'all are still around 4 years later haha: Is this solution intended for spannable strings within a list view where the ListView items themselves are also clickable? I am facing this problem, and when use Joe's second suggestion, setting the movement method, then my spannable string within my layout in the list view becomes clickable but the list view item itself is not clickable. – ThePartyTurtle Jul 01 '15 at 15:51