Automatic 'loading' indicator when calling an async function

前端 未结 6 957
無奈伤痛
無奈伤痛 2020-12-07 23:09

I am looking for a way to automate showing and hiding a \'loading\' message when calling an async service, so instead of doing this:

showLoadingWidget();

se         


        
6条回答
  •  清歌不尽
    2020-12-07 23:50

    You could create a default callback superclass which takes a LoadingMessage object argument in its constructor, and provides hook methods for subclasses, e.g. onSuccess0 and onFailure0.

    The implementation would be similar to:

    public final void onFailure(Throwable caught) {
        loadingMessage.hide();
        onFailure0(caught);
    }
    
    protected abstract void onFailure0(Throwable caught);
    

提交回复
热议问题