Create a web link available in text form (from a ListItem)

In the function ListView Adapter getView(), I have the following:

holder.comment.setText(Html.fromHtml(comment));
holder.comment.setMovementMethod(LinkMovementMethod.getInstance());

holder.commentis TextView.

In the Activity that this ListView contains, I implemented onItemClick Listener. What worked until I turned on

holder.comment.setMovementMethod(LinkMovementMethod.getInstance());

Now the element’s listening element does not work as if this line of code overrides the behavior of clicks. The click event only works on TextView (holder.comment)that opens a link in the browser. Clicking on any other part of the item ListViewdoes not work.

EDIT:

commentsListView
    .setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            Toast.makeText(CommentsActivity.this,"" + arg2,Toast.LENGTH_LONG).show();
        }
    });
+4
source share
2 answers

If any element of the list line contains Focusableor Clickable, then OnItemClickListener will not work.

android:descendantFocusability="blocksDescendants"

list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >

// your other TextView and Other widget here

</LinearLayout>
+4

, xml click listview, descendantFocusability main layout of row xml.

Android: descendantFocusability = "blocksDescendants"

+2

All Articles