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

by jusun...@gmail.com » 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
@Override
    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
@Override
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
/home/bobos26/work/devel/omap_test/packages/apps/Launcher/src/com/
android/launcher/WRGallery.java:27: 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:
 http://android.git.kernel.org/?p=platform/frameworks/base.git ;a=blob;f=core/java/android/widget/AdapterView.java;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.

--
Jon

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


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

by jusun...@gmail.com » Thu, 12 Mar 2009 09:41:39 GMT


 thanks Jon Colverson.
I can see also that mInLayout isn't actually protected, it has
default.
then.....
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. Getting different views in Tabs

I have an app with 2 tabs, the first is a listview, and the second I'm
trying to make a TextView. The problem is I have no idea on how to get
the TextView to show up. The listview is working, but I can't get
anything on the TextView at all. I tried using the Hello, World to try
to work with the text into the tab, but I can't figure it out.

My main.xml section with the TabWidget looks like this:
-----------------------------

    <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <ListView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/itemlist" />
            <TextView
                android:id="@+id/HelloAndroid"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
        </FrameLayout>

-----------------------------
ListView is being used on the java file with the mTabHost code,
-----------------------------

        TabHost mTabHost = getTabHost();

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator
("Answer").setContent(R.id.itemlist));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator
("Ask").setContent(R.id.HelloAndroid));

    mTabHost.setCurrentTab(0);
}
-----------------------------

The TextView is on a different file called HelloAndroid.java, and the
code looks like:
-----------------------------

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}
-----------------------------

How can I fix it so that the 2nd tab brings up the example text?
Thanks!

--

2. build system question : samples

what is the right way to build so that apks which have
LOCAL_MODULES_TAG : = samples
are also included in the system image

-Dan

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. How long does it take for an application to get indexed to the Marketplace?

4. How long does it take for an application to get indexed to the Marketplace?

5. Can someone explain the correct way to use android:layout_toRightOf?

6. Problem with the Emulator

7. Where onItemClick gets called as callback?