Add a new item to recyclerview programatically?


zclin
8/1/2015 4:40 pm
HOME ยป Web Development

I'm still trying to get my head around recyclerview. I have an arraylist, that I use to initialize a recycler view with.

How can I add new items to the recycler view post setting an adapter and layoutmanager?

private void initData() {
        mItems = new ArrayList<String>();
        for (int i = 0; i < ITEMS_COUNT; i++) {
            mItems.add("Item " + (i + 1));
        }
    }

    private void initRecyclerView() {
        mRecentRecyclerView = (RecyclerView)
findViewById(R.id.recentrecyclerView);
        mRecentRecyclerView.setHasFixedSize(true);
        mRecentLayoutManager = new LinearLayoutManager(this);
        mRecentRecyclerView.setLayoutManager(mRecentLayoutManager);



        mAdapter = new RecyclerView.Adapter<CustomViewHolder>()
{
            @Override
            public CustomViewHolder onCreateViewHolder(ViewGroup
viewGroup, int i) {
                View view =
LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.notice_snippet
                        , viewGroup, false);
                return new CustomViewHolder(view);
            }

            @Override
            public void onBindViewHolder(CustomViewHolder viewHolder,
int i) {
                viewHolder.noticeSubject.setText(mItems.get(i));
            }

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

        };
        mRecentRecyclerView.setAdapter(mAdapter);

    private class CustomViewHolder extends RecyclerView.ViewHolder {

        private TextView noticeSubject;

        public CustomViewHolder(View itemView) {
            super(itemView);

            noticeSubject = (TextView)
itemView.findViewById(R.id.notice_subject);
        }
    }

So basically after I initdata() and initRecyclerView(), how do i add a new item to the RecyclerView??


Related to : Add a new item to recyclerview programatically?
Add a new item to recyclerview programatically?
8/1/2015 4:40 pm by zclin in Web Development

I'm still trying to get my head around recyclerview. I have an arraylist, that I use to initialize a recycler view with.

How can I add new items to the recycler view post setting an adapter and layoutmanager?

private void initData() {
        mItems = new ArrayList<Str
RecyclerView Animation on Item Click
31/12/2014 7:10 am by DCal430 in Web Development

I am trying to implement my own recyclerview Animation - I would like to achieve this without using any external libraries. Here is what the theoretical animation should look like.

enter image
description here

The user


RecyclerView scrollbar jumps back to top after first item
20/11/2014 1:20 pm by Marc Dong in Web Development

I created a very basic RecyclerView example.

Layout:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools
How to click on an item inside a RecyclerView in Espresso
15/12/2014 8:30 am by DaveStall in Web Development

I have a RecyclerView (R.id.recyclerView) where each row has an image (R.id.row_image) and a textview. I want to click on the image. I want to click on the image in the first row.
I've tried to use onData(..) but it doesn't seem to work.


How to properly highlight selected item on RecyclerView?
2/12/2014 2:20 am by Brian in Web Development

I am trying to use RecyclerView as horizontal listview. I am trying to figure out how to highlight selected item. When i click one of the item, it gets selected and it is highlited properly but when i click another one second one gets highlighted with the older one.

Here is my onClick fu


Highlight selected item inside a RecyclerView
9/12/2014 11:20 pm by surfsatwerk in Web Development

I'm having trouble with highlighted an item within a RecyclerView, similar to setting the selected item in a ListView.

At the moment, I've set up up the RecyclerView, have a default LayoutManager, and have an adapter which displays all the data. I've just recently got the onClickLis


Implement Swipe Gesture on a RecyclerView Item?
14/11/2014 1:10 am by Kbotei in Web Development

I have seen nice solutions to implement onClick and onLongClick gesture in OnItemTouchListener. What I am looking for now is the code to implement a Swipe Gesture in OnItemTouchListener.

If you have any idea or if you came across a blog or a tutorial , please let me know.Thanks.


RecyclerView with StaggeredGrid, Wrong Item Position
17/11/2014 10:30 pm by overst33r in Web Development

When I load data with images, some item positions are wrong. However, when I scroll this view, these images are positioned correctly.

Examples:

First Load http://i.stack.imgur.com/3MClp.jpg

Scro


Change the margin of first visible item in recyclerview
7/5/2016 5:43 am by greggerz in Web Development

How to change the margin (bottom with 20 dp) of first complete visible item on horizontal recycleview with cards? I can get only the index of first complete visible item but not any reference to the view.

`mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {


Android Robolectric Click RecyclerView Item
21/11/2014 1:50 am by ArmHead in Web Development

Is there any way to simulate a click on a RecyclerView item with Robolectric?

So far, I have tried getting the View at the first visible position of the RecyclerView, but that is always null. It's getChildCount() keeps retu


Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2014 © bighow.org All Rights Reserved .