开发者

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

开发者 https://www.devze.com 2023-01-14 12:04 出处:网络
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.

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.

开发者_Go百科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
// ...


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消