Android ClickableSpan get text onClick()

后端 未结 4 1859
陌清茗
陌清茗 2020-12-05 14:46

I\'m working on ClickableSpan in a TextView, and I\'m trying to get the clicked span\'s text. This is my code.

// this is the text we\'ll be ope         


        
4条回答
  •  無奈伤痛
    2020-12-05 15:12

    A little simpler, could also pass a model reference if necessary.

    public class SpecialClickableSpan extends ClickableSpan {
    
        String text;
    
        public SpecialClickableSpan(String text){
             super();
             this.text = text;
        }
    
        @Override
        public void onClick(View widget) {
             Log.d(TAG, "onClick [" + text + "]");
        }
    }
    

    Then call new SpecialClickableSpan("My Text")

提交回复
热议问题