Question

I implemented ClearableEdittext and it works perfectly except on 4.3 where the logcat floods me with:

W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F....ID 0,0-708,88 #7f050127 app:id/SearchEdittext} during layout: running second layout pass
W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F....ID 0,0-708,88 #7f050127 app:id/SearchEdittext} during layout: running second layout pass
W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F...... 0,0-708,88 #7f050127 app:id/SearchEdittext} during second layout pass: posting in next frame

and when typing in the edittext no text shows up. Also after this starts flooding the logcat, the UI is getting frozen except the soft keyboard.

Cannot find any info on this on the internetz. AndrequestLayout() must be called inside Edittext/Textview class cause I never call it. Do anyone of you know how to fix this or what is causing the bug?

EDIT1 OK, so the problem goes away if I comment out the line:

setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1], x, getCompoundDrawables()[3]);

I tried posting this as a runnable to the view's UI queue but no text shows up.

EDIT2 I have seen this video of an Android Developer explaining that something recursive is happening during onLayout, but once again, I merely subclass EditText.

EDIT3 I also tried discarding the compound drawable and using another ImageView on top of the EditText but it has something to do with the layout passes when drawing something on top of the Edittext I believe... the recursive call is still happening and its blocking the UI. Don't know what to try next... 4.3 sux

EDIT4 I ended up using a linear layout with horizontal orientation and custom 9 patch drawables for the background of the components. In the layout I have a normal edittext with my custom 9patch Bg and then an ImageButton with another custom 9patch Bg.

Something like this:

enter image description here

The red line delimits the Edittext from the ImageButton. It now works on 4.3

Was it helpful?

Solution

A bit late respons, but I just had a related issue with the ClearableEditText component.

It seems that, due to the change of compounddrawables in setClearIconVisible(), an eternal loop of onfocus events are triggered.

I changed the setClearIconVisible to only change the drawable if there are any real change.

   protected void setClearIconVisible(boolean visible) {
        boolean wasVisible = getCompoundDrawables()[2] != null;
        if(wasVisible == visible) return;

        setCompoundDrawables(oldDrawables[0], oldDrawables[1], x, oldDrawables[3]);
        setCompoundDrawablePadding(oldPadding);
    }

That fixed my issue with the keyboard not reappearing. An eternal loop of onfocus-events won't do anyone any good. It still adds another round of layout and focusedChanged, so there might be a more clever solution to this. I'm fine with one extra round, tho.

I've also sent a pull request to the developer, https://github.com/yanchenko/droidparts/pull/31.

OTHER TIPS

try clear method onFocusChange. It helps for me

I ended up using 2 separate views for the edittext and clear btn, see my edited question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top