I have a textview in my app that change the size of a word when click on it, my problem is that if i click this word one time it become bigger, if i click again his size become the double. I need to make it smaller in the second click, by checking the text size of this spannable word before make it bigger.
private ClickableSpan getClickableSpan(final String word,final int start, final int end) {
return new ClickableSpan() {
final String mWord;
{
mWord = word;
}
@Override
public void onClick(View widget) {
TextView tv = (TextView) widget;
// TODO add check if tv.getText() instanceof Spanned
Spanned s = (Spanned) tv.getText();
int start = s.getSpanStart(this);
int end = s.getSpanEnd(this);
Log.d("Sd", "onClick [" + s.subSequence(start, end) + "]");
spans.setSpan(new RelativeSizeSpan(3f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//check the size before make it bigger how to do so??
Toast.makeText(widget.getContext(), s.subSequence(start, end), Toast.LENGTH_SHORT)
.show();
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(Color.WHITE);
}
};
}
I would use a simple boolean isBig
and check it.
if (isBig) {
// make textview smaller
isBig = false;
} else {
// make textview bigger
isBig = true;
}