Skip to content

5.x | EmptyViewHelper

Davide Steduto edited this page Dec 26, 2017 · 8 revisions

In this page


❗️ Note: Available in next release

Introduction

This Helper class is very simple: User provides pre-configured empty views for data and filter result, the helper will show and hides the views in accordance with the Adapter callbacks. Usage (with fragments):

// Empty views handling, should add after FastScroller to better handle it.
mAdapter.addListener(new EmptyViewHelper(mAdapter,
        getView().findViewById(R.id.empty_view),
        getView().findViewById(R.id.filter_view),
        (EmptyViewHelper.OnEmptyViewListener) getActivity()) // Optional see below!!
);

Callbacks

Two new callbacks are provided for optional customization, for instance: user wants to display something else.

/**
 * IMPLEMENT OnEmptyViewListener interface ONLY IN CASE OF MORE CUSTOMIZATION.
 */
public class MainActivity extends AppCompatActivity
        implements EmptyViewHelper.OnEmptyViewListener {

    @Override
    public void onUpdateEmptyDataView(int size) {
        String message = "Refreshed " + size + " items in " + mAdapter.getTime() + "ms";
        Snackbar.make(findViewById(R.id.main_view), message, Snackbar.LENGTH_SHORT)
                .show();
    }

    @Override
    public void onUpdateEmptyFilterView(int size) {
        String message = "Filtered " + size + " items in " + mAdapter.getTime() + "ms";
        Snackbar.make(findViewById(R.id.main_view), message, Snackbar.LENGTH_SHORT)
                .show();
    }
}
Clone this wiki locally