1

我的代码:

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*/

}

如何从“位置”类调用“onSignalStrengthsChanged”方法。

4

1 回答 1

4

您需要创建一个新MyPhoneStateListener实例并调用此实例上的方法。

例如:

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(...);
    }
}

请注意,您只能MyPhoneStateListener在类中创建实例,location因为您将类定义为私有。

另外,请注意doSomething()属于location.

于 2013-10-12T15:07:56.050 回答