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?
This is what I do to reduce the text font in case the text content is large enough to goto the next line. The problem is pretty much the same the only difference in your case is that you want to replace it with some other default text.

```
ViewTreeObserver vto = ((TextView)findViewById(R.id.myTextView)).getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {

                if (null != ((TextView)findViewById(R.id.myTextView))) {
                    if (1 < ((TextView)findViewById(R.id.myTextView)).getLineCount()) {
                    ((TextView)findViewById(R.id.myTextView)).setTextSize(TypedValue.COMPLEX_UNIT_PX,
                              ((TextView)findViewById(R.id.myTextView)).getTextSize() - 2);
                    }
                }

           }
});

```

This would take care of your length dynamically. Now the text size or length cannot be fixed as based on different form factors it would change. For instance a 20 character text in 3.2 inch screen would be decidedly large however it would be too small for 4.1 inch screen. So I would suggest you to use line count as the reference and if the text wraps then you can either reduce the font like I do or replace it by something else.