I have a TextView
with ClickableSpan
in that both layout_height and layout_width is wrap_content.
When the text in TextView
in not too long, it work fine.
When the text is long enough such that it take 2 line, it also work fine but have some strange behavior.
That is when I clicked on the second line's empty space(not fill with text yet but part of TextView
) , the ClickableSpan
onClick()
callback is called.
I do not expect this as I clicked the empty space only but not the spanned text. Although it does not affect much, I want to know what is behind.
I set the ClickableSpan
with below code:
TextView tv = (TextView) findViewById(R.id.text);
tv.setText("TEXT TEXT TEXT TEXT");
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(tv.getText());
ssb.setSpan(new TestClickableSpan(), ssb.length()-5, ssb.length(), 0);
tv.setText(ssb);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setOnTouchListener(new TextViewOnTouchListener());
The TextViewOnTouchListener:
class TextViewOnTouchListener implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("TextView", "onTouch");
return false;
}
}
The TestClickableSpan:
class TestClickableSpan extends ClickableSpan{
@Override
public void onClick(View arg0) {
Log.d("ClickableSpan", "Confirm OnClick: "+arg0.toString());
}
}