![](/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.