开发者

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.

开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜