cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

LoadMore view is not shown on DifferentViewTypeAdapter #353

Open Unlimity opened 8 years ago

Unlimity commented 8 years ago

Hi! I'm having issue with displaying load more in my current app. It's first time I use this library, and I can't figure out what's the problem. Here's my code:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(mIsTabBarEnabled ? R.layout.fragment_list_tabbed : R.layout.fragment_list_untabbed, container, false);

        //mSwipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_layout);
        mRecyclerView = (UltimateRecyclerView) rootView.findViewById(R.id.ultimate_recycler_view);

        mRecyclerView.setInflater(inflater);
        mRecyclerView.setEmptyView(R.layout.view_list_empty, UltimateRecyclerView.EMPTY_CLEAR_ALL);
        mRecyclerView.setLoadMoreView(R.layout.view_load_more);
        mRecyclerView.setOnLoadMoreListener(mOnLoadMoreListener);
        mRecyclerView.setDefaultOnRefreshListener(mOnSwipeRefreshListener);
        mRecyclerView.setLayoutManager(new ScrollSmoothLineaerLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false, 300));
        mRecyclerView.setHasFixedSize(false);

        return rootView;
    }

After creating view, I start items downloading:

    @Override
    public void onStart() {
        super.onStart();

        if (mAdapter == null) {
            mAdapter = new MovieListAdapter(new ArrayList<TZMovie>());
            mRecyclerView.setAdapter(mAdapter);

            mRecyclerView.setRefreshing(true);

            runOperation(new GetMoviesOperation(mIsFreeEnabled, mIsRecommended, mCategoryId, mContextId, 0),
                    TAG_GET_MOVIES_OPERATION + MovieListFragment.this.hashCode());
        }
    }

And after download I add downloaded items in my adapter:

    public void onOperationFinished(final GetMoviesOperation.Result result) {
        mRecyclerView.setRefreshing(false);

        if (!mRecyclerView.isLoadMoreEnabled()) {
            mRecyclerView.reenableLoadmore();
        }

        GetMoviesOperation operation = (GetMoviesOperation) result.getOperation();

        if (result.isSuccessful()) {
            if (operation.isZeroOffset()) {
                mAdapter.setItems(result.getOutput());
                mRecyclerView.setItemViewCacheSize(operation.getTotal() - result.getOutput().size());
            } else {
                if (result.getOutput().size() > 0) {
                    mAdapter.addItems(result.getOutput());
                } else {
                    mRecyclerView.disableLoadmore();
                }
            }
        } else {
            if (mAdapter.getItemCount() == 0) {
                mRecyclerView.showEmptyView();
            }

            // TODO
            Toast.makeText(getContext(), result.getErrorMessage(), Toast.LENGTH_LONG).show();
        }
    }

After that when I scroll down loadMore method gets invoked, but my load more layout is not visible. Here's also layout of load more

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp" >

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</FrameLayout>

Can somebody point me out how to fix this issue? Thanks in advance!

jjhesk commented 8 years ago

i see where is your problem. remember you need to fully initialize the recyclerview by having the adapter to be set at the first place and you have skipped.

Unlimity commented 8 years ago

You mean that I need to set adapter right after layout inflation and before any other manipulations with it (e.g. setting empty view, load more, layout manager, etc.)?

jjhesk commented 8 years ago

remember that setadapter is the very last setup to initialize recyclerview

isamed commented 6 years ago

can you show me your adapter class plz... i am stuck with adapter class