access parent's protected variable when extend a android class!

by » Tue, 10 Mar 2009 16:48:43 GMT

Sponsored Links
 I liked to extend a Gallery widget class, so I tried to extend and
I faced the problem of using protected variable.

this is a Gallery source
    protected void onLayout(boolean changed, int l, int t, int r, int
b) {
        super.onLayout(changed, l, t, r, b);
         * Remember that we are in layout to prevent more layout
request from
         * being generated. [android comment]
        mInLayout = true;
        layout(0, false);
        mInLayout = false;
and I changed
protected void onLayout (boolean changed, int l, int t, int r, int b)
    super.onLayout (changed, l, t, r, b);
    mInLayout = true;
    MyLayout (0, false);
    minLayout = false;

I build.. and result is
android/launcher/ mInLayout is not public in
android.widget.AdapterView; cannot be accessed from outside package
        mInLayout = true;
the result log mean that I can't accessed the protected variable
mInLayout from outside package. I think I can access a parent's
protected variable when extending class in Object oriented
programming theory. am I wrong? and is there a good solution to access
a parent's protected variable?


access parent's protected variable when extend a android class!

by Jon Colverson » Tue, 10 Mar 2009 23:22:24 GMT


You're correct that a subclass can access its parent's protected
variables, but if you look at the AdapterView source: ;a=blob;f=core/java/android/widget/;h=173e80f54f75ee3051ac8e774ce18b4c9338eea8;hb=HEAD

you can see that mInLayout isn't actually protected, it has default
(package) visibility. I'm not sure what the solution is for your
particular problem.



Sponsored Links

access parent's protected variable when extend a android class!

by » Thu, 12 Mar 2009 09:41:39 GMT

 thanks Jon Colverson.
I can see also that mInLayout isn't actually protected, it has
but when I build, build log tell me that I cannot access mInLayout
from outside package
please. help me!! nobody know the reason?


Other Threads

1. format for progressbar drawable xml?

Does anybody know the proper format for declaring custom horizontal  
progressbar drawables in xml? I've searched and searched, but the only  
documentation/discussions I can find are for custom button graphics,  
which seem to work via a different system.

Allan Hsu <allan at counterpop dot net>


2. GridView: how to select, programmatically?

This is driving me up a wall...

I want to have a GridView, containing four icons, and I want the first 
icon to be pre-selected when the activity is opened. This wouldn't seem 
too tough, but I'm obviously blanking on how to make it work.

Some sample code:

The layout is just a GridView in a LinearLayout. The four icons 
referenced in the Java are just some random icons. They all appear nice 
in a row...just none are selected.

I have grid.setSelection(0), but it does not seem to do anything.

I have tried various ways of augmenting the code, including:

-- calling grid.requestFocus() before grid.setSelection(0)
-- calling grid.invalidate() after grid.setSelection(0)
-- calling grid.requestLayout() after grid.setSelection(0)
-- delaying the grid.setSelection(0) via postDelayed() to ensure it gets 
called after onCreate() finishes
-- putting the grid.setSelection(0) in onResume(), which is NOT what I 
want, but I'm getting desperate

The GridView selection works fine...once somebody presses the D-pad to 
navigate the four icons. The selector (stock one from Android) shows up 
quite nicely. I just want the first icon to be pre-selected, so the UI 
is consistent -- there is *always* one icon highlighted. It is the only 
widget in the layout, so there should be no question of who has the focus.

What am I doing wrong?

Thanks in advance!

Mark Murphy (a Commons Guy)
_The Busy Coder's Guide to Android Development_ Version 1.3 Published!


3. java.lang.VerifyError in Android

4. When ever i run a mail application, ANdroid emulator say sorry (process )stops unexpectedly

5. Nokia & Visa tie up...

6. Web links without showing the URL

7. Video Review of T-Mobile G1