Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Did you try setting the background of your TextView to Android's default <code>list_selector_background</code>?</p> <pre><code> textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setBackgroundResource(android.R.drawable.list_selector_background); </code></pre> <p>For me it seems to give the result that you want.</p> <p><strong>UPDATE: After seeing that the item is not just a single TextView</strong></p> <p>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. </p> <p>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 <code>onItemClick()</code> (after a click is definitely confirmed) to see if we should launch the <code>onClick()</code> on our ClickableSpans:</p> <pre><code>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&lt;?&gt; 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; } }); // ... } } </code></pre> <p>The <code>spanClicked()</code> method is basically an abbreviated version of the LinkMovementMethod's <code>onTouchEvent()</code> method in the framework. To capture the last MotionEvent coordinates (to check for the click event), we simply add an OnTouchListener on our ListView.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload