Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why setting text from onMeasure does not affect TextView?

There is a TextView of a certain size and whenever text set to it is too long I'd like to re-set it to some preset value.

To accomplish this I am overriding onMeasure and calling setText. However this does not affect the TextView contents.

What am I missing?

EDIT: if you think that it should be done in a completely different way - please feel free to suggest

like image 690
Asahi Avatar asked Aug 04 '11 11:08

Asahi


1 Answers

onMeasure() is usually called during layout phase. Besides as far as I know onMeasure() is where YOU have to measure your view. It receives 2 values which are the size of the parent of your view which may be constant.

Why don't you just check the length of the text you're setting and if it's too long just replace it with your default one?

like image 185
EvilDuck Avatar answered Sep 25 '22 16:09

EvilDuck