简体   繁体   中英

How to access public method present inside private class

My Code:

public class location
{

private class MyPhoneStateListener extends PhoneStateListener
    {
       //Get the Signal strength from the provider, each time there is an update 
      @Override
      public void onSignalStrengthsChanged(SignalStrength signalStrength)
      {

      }
/*some text*/

}

how can i invoke "onSignalStrengthsChanged" method from "location" class.

You need to create a new MyPhoneStateListener instance and invoke the method on this instance.

For example:

public class location {

    private class MyPhoneStateListener extends PhoneStateListener {
      //Get the Signal strength from the provider, each time there is an update 
      @Override
      public void onSignalStrengthsChanged(SignalStrength signalStrength)
      {

      }
      /*some text*/

    }

    public void doSomething() {
        PhoneStateListener listener = new MyPhoneStateListener();
        listener.onSignalStrenghtsChanged(...);
    }
}

Please notice that you can only create a MyPhoneStateListener instance in the location class because you defined the class private.

Also, notice that doSomething() belongs to location .

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