简体   繁体   中英

I want to access inner class variable from my Outer class method in Android Activity

Is someone intelligent there who can answer this question?

I m doing some task with following code, I want to access inner class variable from outer class method.

class Outer extends Activity
{

 private Handler mHandler = new Handler();

  StopTheThread()
  {
     mHandler.removeCallbacks(mUpdateTimeTask);// this is the wat i want to do
  }

  class Inner 
  {
     final Runnable mUpdateTask = new = new Runnable() {
           public void run() {

           //Some Code Goes Here

       }
     };

     InnerClassMethod()
     {

       mHandler.removeCallbacks(mUpdateTimeTask);// This statement working fine here
      } 

  }

}

Here mUpdateTask is inner class variable which is not accessible from outer class Pleas Tell me how can i write that line

You need an instance of Inner to access the mUpdateTask variable.

Something like:

Inner inner = new Inner();
inner.mUpdateTask
// ...

Create an Inner class object and then access it

Inner inner = new Inner();
inner.mUpdateTask
// use this 

OR

you can create a static mUpdateTask object and can access it using class name

Inner.mUpdateTask

just make the mUpdateTask static ... and call with inner class name.. Inner.mUpdateTask

also you can use getters which will be able to retrun the mUpdatetask.

if you are creating object of this Innerclass i really dont see any point of this question.. you can always call in the way Vivien described above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM