2013-03-26 26 views
0

在此示例中,我有一個正在播放mp3歌曲的應用程序,但公司有不同的許可證檢查。Android:從庫中調用覆蓋類的方法

所以在我的圖書館我有3個文件:

public interface UserCheckerInterface { 
    public void appIsEnabled(boolean result); 
} 

public class UserChecker { 

    public static void appisEnabled(final UserCheckerInterface userCheckerInterface) { 
     userCheckerInterface.appIsEnabled(true); 
    } 

} 

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(final Bundle savedInstanceState) { 

     .... 

     UserChecker.appisEnabled(new UserCheckerInterface(

      @Override 
      public void appisEnabled(final boolean result) { 
       Toast.makeText(getApplicationContext(), "" + result, 0).show(); 
      } 

     )); 

    } 

} 

我想覆蓋我的應用程序的UserChecker.appisEnabled方法,其使用這個庫,但我不知道怎麼辦。

回答

1

我不知道我是否已經明白你的問題,如果我這樣做,比你只需要實現你的界面通過寫

public class UserChecker implements UserCheckerInterface{ 

    @Override 
    public static void appisEnabled(final UserCheckerInterface userCheckerInterface) { 
     userCheckerInterface.appIsEnabled(true); 
    } 

} 

一旦你這樣做,那麼IDE會顯示一個錯誤,如果您尚未實施該方法;在這種情況下情況並非如此。

+0

我只是想從我的圖書館打電話過度的方法 – Robertoq 2013-03-26 15:32:51

+0

你可以重新解釋請因爲我不明白上述評論:) – test 2013-03-26 16:40:45