Question: I have the following jQuery code:

```
$('#foo').click(function ()  {
    var loading = $('<img id="loading" src="images/loader.gif" alt="loading" />');
    $('#stars').prepend(loading);
    alert('WAIT');
});

$('#bar').click(function ()  {
     $('#stars').empty();
});

```

When first clicking `#foo` the image is being shown in my browser window. After clicking `#bar` and then `#foo` again the image is not being shown.

I use Chrome and also use the `Inspect Element` tool and I can see in the code that the `img` tag was added in `#stars` when clicking for the second time `#foo`. But no `img` is being shown in the browser window.

Any ideas why? Should I use the `live()` function perhaps, but how?

Answer: 
`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?
You could register a custom `TextWatcher` with `addTextChangedListener (TextWatcher watcher)`.

Inside the `TextWatcher` you would override the `afterTextChanged(Editable s)` function, mesure the lenght of the text, and if too long, set it back to your default text.

EDIT: I'm not too sure about this, but this is why I think your solution with onMeasure is not working: onMeasure is called on the initial layout phase, or when the UI needs to be resized, so once your UI is set, if you change the text of the UI afterwards, and the text becomes too long, this doesn't affect the size of the TextView, and onMeasure is not called again...

AnyWay better to just look out for text changes, and do what you want when it's over a limit, and let Android do the dirty TextView measurement work