0
我正在使用Android Image Slider庫來顯示滑塊上的圖像。但是,某些圖像未加載,因爲後端需要驗證。所以我需要一個監聽器來加載圖像。Android應用程序模塊中未調用Android庫模塊的接口方法
這是庫:在抽象BaseSliderView類裏面,有ImageLoadListener接口。我使用setOnImageLoadListener方法設置監聽器。
public abstract class BaseSliderView {
.....
private ImageLoadListener mLoadListener;
.....
protected void bindEventAndShow(final View v, ImageView targetImageView){
....
rq.into(targetImageView,new Callback() {
@Override
public void onSuccess() {
if(v.findViewById(R.id.loading_bar) != null){
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
}
}
@Override
public void onError() {
if(mLoadListener != null){
mLoadListener.onEnd(false,me);
}
if(v.findViewById(R.id.loading_bar) != null){
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
}
}
});
}
/**
* set a listener to get a message , if load error.
* @param l
*/
public void setOnImageLoadListener(ImageLoadListener l){
mLoadListener = l;
}
.....
public interface ImageLoadListener{
void onStart(BaseSliderView target);
void onEnd(boolean result,BaseSliderView target);
}
.....
}
我檢查,當圖像未加載時,在庫模塊中調用接口onEnd方法。
但是應用模塊,onEnd方法甚至沒有在庫模塊的叫法叫。
這究竟是爲什麼?不應該在應用程序模塊中調用onEnd方法?如何解決這個問題呢?
你看看你的AndroidMonitor來檢查錯誤嗎? 嘗試'Log.i(「開始」)'而不是'MyLog.log(「開始」)'; – 2017-04-01 18:43:15
它看起來像是被打了某種方式。 'mLoadListener'是你的匿名類的一個實例嗎? – tynn
是的,我檢查了AndroidMonitor檢查錯誤 - 沒有日誌。 onEnd方法根本不被調用。 –