Hi,
Just did this. Actually the problem was not a mSelectedTab = -1,
but rather a mSelectedTab = 1 and a getChildCount = 1. This
problem I do not seen on Android 4.0.3.

The workaround code that works for me is:

public class TabWidgetFix extends TabWidget {
    private final View dummy;

    /**
     * <p>Create a tab widget fix.</p>
     * @param c The context.
     */
    public TabWidgetFix(Context c) {
        super(c);
        dummy = new View(c);
    }

    /**
     * <p>Retrieve a child tab view.</p>
     *
     * @param i The index.
     * @return The child tab view.
     */
    public View getChildAt(int i) {
        if (i < 0 || i >= getChildCount())
            return dummy;
        return super.getChildAt(i);
    }

}

But there remains one minor problem. I use the
clearAllTabs() based code:

        tabHost.clearAllTabs();
        tabHost.addTab(spec);

Since there is no removeTab API available. But now
some of the sub activities in the activity loose their
blinking cursor.

Bye
Kostya Vasilyev schrieb:
You could try extending the framework class and overriding relevant methods.

16 февраля 2012 г. 15:58 пользователь Jan Burse<[email protected]>  написал:
Dear All,

Is there some workaround for a null pointer exception
in TabWidget. It basically happens in the following code:

        tabHost.clearAllTabs();
        tabHost.addTab(spec);

The clearAllTabs sets the mSelectedTab to -1. The problem is
some sloppy code in the Android 2.3.7 version of TabWidget:

337    public void  setCurrentTab(int index) {
[...]
342        getChildTabViewAt(mSelectedTab).setSelected(false);

The crash is in 342 since getChildTabViewAt returns null
when mSelectedTab == -1.

This was fixed in the Android 4.0.3 version or maybe before
of TabWidget:

386    public void  [More ...] setCurrentTab(int index) {
[...]
391        if (mSelectedTab != -1) {
392            getChildTabViewAt(mSelectedTab).setSelected(false);
393        }

How would one go about to workaround the problem in Android 2.3.7?

Bye


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to