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. How to prevent AdView from taking the D-Pad Focus

I installed the AdMob AdView on the ImageSwitcher example from the
Google provided APIs.  Easy enough.

Here's the problem:  Whereas before I was able to change pictures
using either the Directional Pad (DPAD) on the device (or the arrow
keys on a computer keyboard), now the AdView is taking that focus.
How can I give the focus back to the ImageSwitcher?


<?xml version="1.0" encoding="utf-8" ?>
 <RelativeLayout xmlns:android="
android" xmlns:app="
com.morgan.alawaiapps.picturesofstuff" android:id="@+id/relative"

<LinearLayout android:orientation="vertical"
  < android:id="@+id/ad"
android:layout_height="wrap_content" app:backgroundColor="#000000"
app:textColor="#FFFFFF" app:keywords="Android application"
app:testing="true" android:focusable="false" />

  <ImageSwitcher android:id="@+id/switcher"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" />

  <Gallery android:id="@+id/gallery" android:background="#55000000"
android:layout_width="fill_parent" android:layout_height="60dp"
android:gravity="center_vertical" android:spacing="16dp" />


2. Eh tau ngga....:-)

Yg bikin iklan g update teknologi neh...
Payah...ngejatohin pengguna android aja...


send from Motorola Milestone + xL unlimiteD

Baru sempet buka koran, kan ada iklan indosat android tuh di kompas senin 22
feb , halaman 19, nih saya attach.
Lihat deh baik2, wallpaper belakang memang semua wallpaper android, tapi
perhatiin deh outline gambar handphone nya....
Tau ngga itu handphone apa?


Hahahahaha, hidup steve jobs.... pasti nih iklan dibuat di macbook....yg
buat penggemar ipun......
Bisa marah nih google brader...


Lucky Sebastian
Pake nexus desire...

"Indonesian Android Community [id-android]"

3. Json Exmpale

4. Best way to expose my Activity to third parties?

5. Camera on HTC Hero: Calling camera.autoFocus(...) gives a IOException .. ?

6. Camera on HTC Hero: Calling camera.autoFocus(...) gives a IOException .. ?

7. Broadcast intent for USB power?