![](/img/trans.png)
[英]How do I execute the function public method declared inside a class which is in turn inside a private method?
[英]How to access public method present inside private class
我的代码:
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”方法。
您需要创建一个新的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(...);
}
}
请注意,您只能在location
类中创建MyPhoneStateListener
实例,因为您MyPhoneStateListener
类定义为private。
另请注意, doSomething()
属于location
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.