我的代码:
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*/
}
如何从“location”类调用“onSignalStrengthsChanged”方法。
答案 0 :(得分: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
。