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.42k forks source link

Add progressbar to custom adapter and endless recyclerview #177

Open meness opened 9 years ago

meness commented 9 years ago

Hi,

I'm using this library for the endless list but I don't know how to add the progressbar to the list. How can I add a progressbar?

cymcsg commented 9 years ago

You need to extend UltimateAdapter or you can achieve the feature in your adapter

meness commented 9 years ago

@cymcsg I'm extending that but I couldn't find how to add a progressbar. Can you please give me an example of adding a progressbar? thanks.

meness commented 9 years ago

@cymcsg Please help me with adding a progressbar to the recyclerview when the load more option is enabled.

cymcsg commented 9 years ago

In fact SimpleAdapter is an Adapter which extends UltimateAdapter.The loading more view has been defined as customLoadMoreView.

meness commented 9 years ago

I wrote following codes in my adapter which extends the UltimateViewAdapter but the ProgressBar not showing. Please give me a clear example.

@Override
    public View getCustomLoadMoreView() {
        super.getCustomLoadMoreView();
        View view = View.inflate(context, R.layout.progress_item, null);
        return view;
    }

And the ProgressBar layout content is

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
    android:id="@+id/progress_bar"
    style="@android:style/Widget.Holo.ProgressBar"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:indeterminate="true"/>
cymcsg commented 9 years ago

https://github.com/cymcsg/UltimateRecyclerView/blob/master/UltimateRecyclerView/app/src/main/java/com/marshalchen/ultimaterecyclerview/demo/SimpleAdapter.java

Have you read the source of this?

meness commented 9 years ago

I had read that! I really don't know why you don't give me an clear example! In than simple example, the ProgressBar has defined, but has no usage. So that progress bar will not be used by default. This is my idea. If I'm wrong, please guide me or the best idea is, write about adding progress bar in the documentation clearly. Thanks. I'm waiting for a good answer from you since 4 days ago! Please help me! Thanks.

cymcsg commented 9 years ago

Because I do not know about your code.Have you used enableloadmore method in your demo?

meness commented 9 years ago

I'm really thankful for your time. I give you my adapter and its usage. Please take a look at them and let me know how to add progress bar on load more.

UltimateRecyclerView recyclerView = (UltimateRecyclerView) rootView.findViewById(R.id.urv);
PersonTimelineAdapter mAdapter = new PersonTimelineAdapter(getActivity(), myItems);

recyclerView.setAdapter(mAdapter);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

recyclerView.enableLoadmore();
recyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {@Override
    public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
        // load more data
    }
});
public class PersonTimelineAdapter extends UltimateViewAdapter < CellFeedViewHolder > {

    public PersonTimelineAdapter(Context context,
    List < CompactPostPerson > postList) {
        this.context = context;
        mPosts = postList;
    }

    @Override
    public CellFeedViewHolder getViewHolder(View view) {
        return new CellFeedViewHolder(view,
        false);
    }

    @Override
    public CellFeedViewHolder onCreateViewHolder(ViewGroup viewGroup) {
        View view = LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.fppt,
        viewGroup,
        false);
        CellFeedViewHolder cellFeedViewHolder = new CellFeedViewHolder(view,
        true);

        return cellFeedViewHolder;
    }

    @Override
    public void onBindViewHolder(CellFeedViewHolder viewHolder,
    int position) {
        // ...
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup viewGroup) {
        return null;
    }

    @Override
    public int getItemCount() {
        super.getItemCount();
        return mPosts.size();
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int i) {

    }

    @Override
    public int getAdapterItemCount() {
        return mPosts.size();
    }

    @Override
    public long generateHeaderId(int i) {
        return 0;
    }

    public static class CellFeedViewHolder extends UltimateRecyclerviewViewHolder {

        @Bind(R.id.image_view_post_picture)
        NetworkImageView postPicture;

        public CellFeedViewHolder(View view, boolean isItem) {
            super(view);
            if (isItem) {
                ButterKnife.bind(this, view);
            }
        }
    }
}
cymcsg commented 9 years ago
public class Test extends Activity {
    TestAdapter simpleRecyclerViewAdapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final List<String> stringList = new ArrayList<>();
        stringList.add("111");
        stringList.add("aaa");
        stringList.add("222");
        stringList.add("33");
        stringList.add("44");
        stringList.add("55");
        simpleRecyclerViewAdapter = new TestAdapter(stringList);
        UltimateRecyclerView ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
        ultimateRecyclerView.setHasFixedSize(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        ultimateRecyclerView.setLayoutManager(linearLayoutManager);
        ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
        ultimateRecyclerView.enableLoadmore();
        simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
                .inflate(R.layout.custom_bottom_progressbar, null));
        ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
            @Override
            public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    public void run() {

                    }
                }, 1000);

            }
        });
    }
}
ublic class TestAdapter extends UltimateViewAdapter<TestAdapter.SimpleAdapterViewHolder> {
    private List<String> stringList;

    public TestAdapter(List<String> stringList) {
        this.stringList = stringList;
    }

    @Override
    public SimpleAdapterViewHolder getViewHolder(View view) {
        return new SimpleAdapterViewHolder(view, false);
    }

    @Override
    public SimpleAdapterViewHolder onCreateViewHolder(ViewGroup parent) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recycler_view_adapter, parent, false);
        SimpleAdapterViewHolder vh = new SimpleAdapterViewHolder(v, true);
        return vh;
    }

    @Override
    public int getAdapterItemCount() {
        return stringList.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return 0;
    }

    @Override
    public void onBindViewHolder(SimpleAdapterViewHolder holder, int position) {
        if (position < getItemCount() && (customHeaderView != null ? position <= stringList.size() : position < stringList.size()) && (customHeaderView != null ? position > 0 : true)) {

            ((SimpleAdapterViewHolder) holder).textViewSample.setText(stringList.get(customHeaderView != null ? position - 1 : position));
        }

        }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    public class SimpleAdapterViewHolder extends UltimateRecyclerviewViewHolder {

        TextView textViewSample;
        ImageView imageViewSample;

        public  SimpleAdapterViewHolder(View itemView, boolean isItem) {
            super(itemView);

            if (isItem) {
                textViewSample = (TextView) itemView.findViewById(
                        R.id.textview);
                imageViewSample = (ImageView) itemView.findViewById(R.id.imageview);

            }

        }

        @Override
        public void onItemSelected() {

        }

        @Override
        public void onItemClear() {

        }
    }
}

I have written a sample for just this.I think it'll help you.

kientux commented 9 years ago

Can you check this, UltimateViewAdapter.setCustomLoadMoreView() works with UltimateViewAdapter but not with MultiViewTypesRecyclerViewAdapter. When I scroll down, recycler view still loads more but there's not custom footer view.

cymcsg commented 9 years ago

@kientux MultiViewTypesRecyclerViewAdapter do not have full feature of UltimateViewAdapter in current version.It's need some time to improve it.