Question

I am creating a custom view to represent some kind of a content. I want this content to be scrollable (vertically) and I want standard scroll bars to be visible during the scroll. In order to do this I've included the following code to the cinstructor of my custom view:

setVerticalScrollBarEnabled(true);
setHorizontalScrollBarEnabled(false);
TypedArray a = context.obtainStyledAttributes(R.styleable.View);
initializeScrollbars(a);
a.recycle();

Now, this R.stylable.View is as follows:

<declare-styleable name="View">
    <attr name="android:fadeScrollbars"/>
    <attr name="android:scrollbarAlwaysDrawHorizontalTrack"/>
    <attr name="android:scrollbarAlwaysDrawVerticalTrack"/>
    <attr name="android:scrollbarDefaultDelayBeforeFade"/>
    <attr name="android:scrollbarFadeDuration"/>
    <attr name="android:scrollbarSize"/>
    <attr name="android:scrollbarStyle"/>
    <attr name="android:scrollbarThumbHorizontal"/>
    <attr name="android:scrollbarThumbVertical"/>
    <attr name="android:scrollbarTrackHorizontal"/>
    <attr name="android:scrollbarTrackVertical"/>
    <attr name="android:scrollbars"/>
</declare-styleable>

This code works properly on each and every Android device. Except for the Sony Xperia Z which gives me the NumberFormatException each time it comes across initializeScrollbars(a) :

Caused by: java.lang.NumberFormatException: Invalid int: "25.0dip"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.view.View.initializeScrollbars(View.java:4172)
at TheCustomViewIAmTryingToCreate.<init>(MyCustomView.java:164)
... 36 more

I can see that it interprets some XML-defined value incorrectly but I can not get which one exactly. This line:

at android.view.View.initializeScrollbars(View.java:4172)

points me to the source of View class which I reviewed in order to find the reason. The problem is that initializeScrollbars method (official Android source) has nothing to do with line 4172. Obviuosly Sony (in some way) modified Android on their devices which now makes my code crash.

Does anyone know what causes such a problem or where can I find sources for Android installed on Xperia Z1 (C6903) to look at the reason of this problem?

Edit: This also happens on Xperia Tablet Z (SGP321) and Xperia ZL (C6503)

Was it helpful?

Solution

I still do not know what caused this crash but I have managed to fix it. I ended up extending R.stylable.View with some more attributes:

<declare-styleable name="View">
    <attr name="android:background"/>
    <attr name="android:clickable"/>
    <attr name="android:contentDescription"/>
    <attr name="android:drawingCacheQuality"/>
    <attr name="android:duplicateParentState"/>
    <attr name="android:fadeScrollbars"/>
    <attr name="android:fadingEdge"/>
    <attr name="android:fadingEdgeLength"/>
    <attr name="android:fitsSystemWindows"/>
    <attr name="android:focusable"/>
    <attr name="android:focusableInTouchMode"/>
    <attr name="android:hapticFeedbackEnabled"/>
    <attr name="android:id"/>
    <attr name="android:isScrollContainer"/>
    <attr name="android:keepScreenOn"/>
    <attr name="android:longClickable"/>
    <attr name="android:minHeight"/>
    <attr name="android:minWidth"/>
    <attr name="android:nextFocusDown"/>
    <attr name="android:nextFocusLeft"/>
    <attr name="android:nextFocusRight"/>
    <attr name="android:nextFocusUp"/>
    <attr name="android:onClick"/>
    <attr name="android:padding"/>
    <attr name="android:paddingBottom"/>
    <attr name="android:paddingLeft"/>
    <attr name="android:paddingRight"/>
    <attr name="android:paddingTop"/>
    <attr name="android:saveEnabled"/>
    <attr name="android:scrollX"/>
    <attr name="android:scrollY"/>
    <attr name="android:scrollbarAlwaysDrawHorizontalTrack"/>
    <attr name="android:scrollbarAlwaysDrawVerticalTrack"/>
    <attr name="android:scrollbarDefaultDelayBeforeFade"/>
    <attr name="android:scrollbarFadeDuration"/>
    <attr name="android:scrollbarSize"/>
    <attr name="android:scrollbarStyle"/>
    <attr name="android:scrollbarThumbHorizontal"/>
    <attr name="android:scrollbarThumbVertical"/>
    <attr name="android:scrollbarTrackHorizontal"/>
    <attr name="android:scrollbarTrackVertical"/>
    <attr name="android:scrollbars"/>
    <attr name="android:soundEffectsEnabled"/>
    <attr name="android:tag"/>
    <attr name="android:visibility"/>
</declare-styleable>

Maybe this is too much but my application no longer crashes after that.

Though it is not necessary anymore, still if anyone has any idea on where I went wrong please do not leave me unenlightened.

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