Giter VIP home page Giter VIP logo

rendererrecyclerviewadapter's Introduction

If you like this project you can show support by starring ⭐ this repository 🙏

Renderer RecyclerView Adapter Maven Central API Donate

Articles & Presentations

Examples

All View Renderer Composite Load More
Example Example Example Example
ViewState Diff Util Payload
Example Example Example

Wiki

https://github.com/vivchar/RendererRecyclerViewAdapter/wiki

Gradle

dependencies {
    compile 'com.github.vivchar:RendererRecyclerViewAdapter:3.0.1'
}

Usage

  • Step 1: Add the ViewModel interface to your UI model
public class SomeModel implements ViewModel {
	...
}
  • Step 2: Create your item_layout
<LinearLayout ... >
	<TextView android:id = "@+id/title" ... />
	<ImageView android:id = "@+id/image" ... />
	<Button android:id = "@+id/button" ... />
	<CustomView android:id = "@+id/custom" ... />
</LinearLayout>
  • Step 3: Initialize Adapter and register the ViewBinder
mRecyclerViewAdapter = new RendererRecyclerViewAdapter();

mRecyclerViewAdapter.registerRenderer(new ViewRenderer<>(
	R.layout.item_layout,
	SomeModel.class,
	(model, finder, payloads) -> finder
		.find(R.id.custom, (ViewProvider<CustomView>) customView -> { ... })
		.setBackground(R.id.image, model.getBackground())
		.setText(R.id.text, model.getText())
		.setOnClickListener(R.id.button, v -> { ... })
));

mRecyclerViewAdapter.registerRenderer(...); /* you can use several types of cells */

/* Regular code:
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mRecyclerViewAdapter);

mRecyclerViewAdapter.setItems(getItems());
mRecyclerViewAdapter.notifyDataSetChanged();
*/

Release notes

See the Releases Page

Migrations

Projects using RendererRecyclerViewAdapter

  • Camfrog: Group Video Chat;
  • Paltalk: Free group video calls & chat rooms;
  • DeskRoll: Gives you secure remote access to computers;
  • MedikTest: Preparation for accreditation of doctors;
  • KFormMaster: Easily build generic forms with minimal effort;
  • KDV Online: Online store of KDV, Russian producer of snacks and confectionery products, whose goods are well known and beloved not only in Russia but also well beyond.

Send me a pull request with modified README.md to get a shoutout!

Communication

  • If you need help, please use Stack Overflow.
  • If you found a bug, please open Issue.
  • If you have a feature request, please open Issue.
  • If you want to contribute, please submit Pull request.

License

Copyright 2017 Vitaly Vivchar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

rendererrecyclerviewadapter's People

Contributors

alaytsev avatar nadstas avatar thejuki avatar vivchar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rendererrecyclerviewadapter's Issues

Formatting

I really appreciate the idea, but I just have to ask, what's the idea behind this kind of formatting?

public
class SomeViewHolder
		extends RecyclerView.ViewHolder
{

At the same time, fields have "regular" formatting:

public final TextView mTitle;

Probably from library-user perspective it doesn't really matter, but it's still kinda hard to read.

createViewHolder of ViewRenderer is called as many times as there are items in list

First of all - thank you for your lib.
I'm using it with ViewRenderer, as I have complex list items and prefer to write my own renderer for it. Also - I'm using CompositeViewRenderer. And here is the problem - createViewHolder of child view renderer is called for all items in list of childs, while I believe it should be called as many times as there items on screen. It is problem because my views are "heavy" and full list inflating takes time. Not a problem if you have only list one on screen, but I have viewpager with lists on every page, and page swiping is laggy even on modern phone.
My createViewHolder method is absolutely simple:

override fun createViewHolder(parent: ViewGroup?): GameEventViewHolder { return GameEventViewHolder(inflate(R.layout.list_item_game_event_constraint, parent)) }

Maybe I'm using it in wrong way?

How to add a custom paging adapter

Hello, I read the instructions and I know this issue page is for issue only reporting but I feel my question can only be answered by you.

Question.
How do I add a custom adapter implementation to your adapter or ViewBinder.
My implementations involves various having multiple composite items and one of the items requires me to have an auto scroll recyclerview for banner items. (Looping viewapager)

I’d like to know if it can be integrated in your adapter

Please make layout orientation in CompositeViewRenderer configurable

Thank you for your nice library.

In CompositeViewRenderer.java,

@nonnull
protected RecyclerView.LayoutManager createLayoutManager() {
return new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, fa
lse);
}

layout orientation is fixed to horizontal, please make this configurable so I can set to vertical or horizontal depending on my needs, thanks!

Simple thought

Probably in the adapter it is better to use something like:

    @NonNull
    protected final Map<Integer, ViewRenderer> mRenderers = new HashMap<>();

And later in the adapter methods just check mRenderers.get(type) == null
for instance:

    public void registerRenderer(@NonNull final ViewRenderer renderer) {
            mRenderers.put(renderer.getType(), renderer);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, final int type) {
        ViewRenderer renderer = mRenderers.get(type);
        if (renderer != null)
            return renderer.createViewHolder(parent);
        throw new RuntimeException("Could not find renderer of type: " + type);
    }

etc

Items repeating when slide down in recycler view

Thanks for the great library! I have been using this library for my project, but while using it, adapter.setItems() is making items in recycler view to repeat.

        mRendRecy.registerRenderer(getFlistViewBinder());
        mRendRecy = new RendererRecyclerViewAdapter();
        mRendRecy.registerRenderer(getFlistViewBinder());
        mRendRecy.enableDiffUtil();
        mRendRecy.setDiffCallback(new FListDiffUtilCallback());
        mRendRecy.setHasStableIds(true);
        mRecyclerView.setAdapter(mRendRecy);
        List<FListViewModel>mList =new LinkedList<>();
            for (ToTal_ProfileModelRealmClass mObj:resultRealm1.subList(0,17)){
                FListViewModel mOb=new FListViewModel();
                mOb.setUserId(mObj.getUserId());
                mOb.setName(mObj.getName());
                mList.add(mOb);
                Log.e("SahajLOG564", "mName>> " +mObj.getName());
            }
            Log.e("SahajLOG564", "list01>> " +mList);
            Log.e("SahajLOG564", "list02>> " +mList.size());

            mRendRecy.setItems(mList);


    private ViewRenderer getFlistViewBinder() {
        return new ViewBinder<>(
                R.layout.item_chat_adapter, /* your item layout */
                FListViewModel.class, /* your model class */
                (model, finder, payloads) -> finder
                        .setText(R.id.item_flist_name, model.getName())
                        .setText(R.id.item_flist_div1,model.getFirstLetters(model.getDiv1Name()))
        );
    }

            ````

Any plan to upgrade to Kotlin?

While current version is working in kotlin, is there any plan to upgrade the source code to kotlin too?
i tried to manually convert them one by one, but it keep get cyclic error betwen * types and ViewModel ViewHolder generic types.

pagination

how can I implement pagination? every time I do setItems recycler view return to top. and if call notifydatasetchanged than nothing change

Renderer for model type

Hello,

I was looking to migrate to the latest version and saw that you removed the types that were bound to the Renderer what it was registered with the Adapter.

I was wondering is there anyway to implement/emulate that behavior in the latest version?

It can theoretically be done with different model types, but receiving some type when inflating the layout and then deciding which layout to inflate would be much cleaner imho.

Regards,
Viktor

How to add sections in Recyclerview

I am looking for recyclerview library for my project. But it has specific requirement of sections in recyclerview.
Some time sections should be scroll able and some time sticky sections.
I don't have tried this library that's why not asked on stackoverflow.
But before starting i want to confirm so I don't have to change it later on.

So How to add sections in Recyclerview with your library ?

How to get Position?

For animating items in ViewBinder method, I need to check if RecyclerView is scrolling up or down. In custom adapters, I usually add a global variable LASTPOSITION and compare it to current position for detecting up or down scroll for proper animation. How can we do so in RendererRecyclerViewAdapter? Also, how can access adapterPosition or position in ViewBinder?

FYI:

  @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int position) {
           Animation animation = AnimationUtils.loadAnimation(mActivity, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
         viewHolder.itemView.startAnimation(animation);
         lastPosition = position;
}

Image not shown via URI

Here is my code

mRecyclerViewAdapter.registerRenderer(new ViewBinder<>(R.layout.item_list_produk, Produk.class, (model, finder, payloads) -> finder .setText(R.id.item_product_name, model.getNamaProduk()) .setText(R.id.item_product_price, getResources().getString(R.string.txt_caption_selected_money).concat(" ") .concat(String.valueOf(model.getHarga()))) .setText(R.id.item_product_durability, String.valueOf(model.getKetahanan()).concat(" ") .concat(getResources().getString(R.string.txt_caption_hours_durability))) .setText(R.id.item_product_uom, model.getSatuan().concat(" ") .concat(getString(R.string.txt_caption_product_uom))) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mActivity.showDetail(model); } }).setImageURI(R.id.item_list_produk_image, "http://www.example.com/image.jpg") ));

RecyclerViewHolder.java

Hi, it is not defined in recycler in the document,

public class RecyclerViewHolder
		extends CompositeViewHolder
{
	public RecyclerViewHolder(@NonNull final View view) {
		super(view);
		recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
	}
}

and how to add the adapter to this.

DefaultDiffCallback with nested RecyclerView

I tried posting my question to stackoverflow (this is my first time posting to stackoverflow) and I have to yet figure out how to do the formatting on stackoverflow correctly (now it doesn't look right), so I'm asking my question here.

I don't know how to handle the following scenario, please advise.
Thanks for your help!

ParentRecyclerView -> ChildRecyclerView
For each item on the ParentRecyclerView, there is a button to delete the specific parent item
For each item on the ChildRecyclerView, there is a button to delete the specific child item
e.g

parent item A

| child item C, button C |
| child item D, button D |

                        button A

parent item B

| child item E, button E |
| child item F, button F |

                       button B

click button A will delete parent item A, click button C will delete child C, and so forth

parentAdapter = new RendererRecyclerViewAdapter();
parentAdapter.setDiffCallback(new ParentDiffCallback());
public class ParentDiffCallback extends DefaultDiffCallback {
public boolean areItemsTheSame(@nonnull final ParentModel oldItem, @nonnull
final ParentModel newItem) {
return oldItem.getId().equals(newItem.getId());
}
}

When I click on button A, parent item A (including child item C and D) will disappear from the ParentRecyclerView, which is exactly what I want.
But when I click on button E, I don't know what I should have in ParentDiffCallback to make child item E disappear from the ChildRecyclerView, I want it to look like the following:

parent item B

| child item F, button F |

                       button B

I tried the following code and it didn't work:

@OverRide
public boolean areContentsTheSame(@nonnull final ParentModel oldItem, @nonnull final ParentModel newItem) {
List old_ids = new ArrayList<>();
List new_ids = new ArrayList<>();
for (ChildModel old_cm : oldItem.getItems()) {
old_ids.add(old_cm.getId());
}
for (ChildModel new_cm : newItem.getItems()) {
new_ids.add(new_cm.getId());
}
return old_ids.equals(new_ids);
}

areContentsTheSame always returns true

ViewState not working

I just cloned your project but the view state is not working as per the way it is showing in gif..when I come back above the views are recycled and horizontal scroll goes to 1st position

setItems() always replace current items

adapter.setDiffCallback(ItemsDiffCallback())
adapter.setItems(projectsList.data)
class ItemsDiffCallback : DefaultDiffCallback<ViewModel>() {

    override fun areItemsTheSame(oldItem: ViewModel, newItem: ViewModel): Boolean {
        if (oldItem is ProjectsList.Data) {
            return if (newItem is ProjectsList.Data) {
                oldItem.id == newItem.id
            } else {
                false
            }
        } else if (newItem is ProjectsList.Data) {
            return false
        }
        return super.areItemsTheSame(oldItem, newItem)
    }

    override fun areContentsTheSame(oldItem: ViewModel, newItem: ViewModel): Boolean {
        return super.areContentsTheSame(oldItem, newItem)
    }

    override fun getChangePayload(oldItem: ViewModel, newItem: ViewModel): Any? {
        if (oldItem is ProjectsList.Data) {
            if (newItem is ProjectsList.Data) {
                val payload: ArrayList<Long> = ArrayList()
                payload.add(System.currentTimeMillis())
                return payload
            }
        }
        val payload = super.getChangePayload(oldItem, newItem)
        return payload
    }

}

Inside ProjectsList.Data:

override fun equals(obj: Any?): Boolean {
            if (obj is Data) {
                val pm: Data = obj
                return pm.id == this.id
            }
            return false
        }

So, always when i use setItems(projectsList.data) its replace my current list by projectsList.data (items various). Собственно, how to добавить элементы в список не перезаписав текущие?

ViewState not working as expected

Hi!

First of all i want to thank you for this library!

I think i encountered a problem with the viewstate. It doesn´t work like expected and the behaviour can be reproduced with your given example app.

  • run the app
  • open view state
  • scroll the first item horizontally
  • scroll down
    => some elements have the same view state as the first item

This behaviour first occured in an example i made:

  • i created a recycler view with switches
  • after i opened the fragment i changed the view state of one item
  • than i scrolled the view
    => some elements were checked

The strange thing: when i first scroll the view and change afterwards the state of the items this bug doesn´t occure. So i downloaded your example to check if i made something wrong. But also in your example i was able to reproduce this unexpected behaviour.

Maybe you can try to reproduce this behaviour. Please let me know if im doing something wrong or you have a solution for this problem.

Drag and drop support

First of all, awesome library, I have been using it for all of my apps.
So my question is, what would be the easiest way to support drag and drop with this library? I use this library to have lists with different row types and one obvious thing with drag and drop feature is that I don't want the user to drag and drop a row into rows of a different type.

Position of ViewModel?

I have a List allModel. allModel have size is 15. I see bindView in ViewRerender have paramete is ViewModel, not positon, how i get postion when click the row, can't you help me?
Thanks.

ViewState overrides value from Model

  1. create list with EditTexts
  2. create viewstate
  3. save value of edit text
  4. viewmodel of editText also has this value
    5 open list
    Result: empty value

Also I created InputFragment to demonstrate this

renderer.performBindView(item, holder);
restoreViewState(holder);

//...

protected void restoreViewState(@NonNull final ViewHolder holder) {
	if (holder.isSupportViewState()) {
		final ViewState viewState = mViewStates.get(holder.getViewStateID());
		final boolean hasSavedViewState = viewState != null;

		if (hasSavedViewState) {
			viewState.restore(holder);
		} else {
			clearViewState(holder);
			if (hasChildren(holder)) {
				getChildAdapter((CompositeViewHolder) holder).clearViewStates();
			}
		}
	}
}

should be:

clearViewStateifNeed(holder); /* we should clear previous view state before bindView */
renderer.performBindView(item, holder);
restoreViewState(holder); /* we should restore view state after bindView */

//...

protected void clearViewStateifNeed(@NonNull final ViewHolder holder) {
	if (holder.isSupportViewState()) {
		final ViewState viewState = mViewStates.get(holder.getViewStateID());
		final boolean hasSavedViewState = viewState != null;

		if (!hasSavedViewState) {
			clearViewState(holder);
			if (hasChildren(holder)) {
				getChildAdapter((CompositeViewHolder) holder).clearViewStates();
			}
		}
	}
}

protected void restoreViewState(@NonNull final ViewHolder holder) {
	if (holder.isSupportViewState()) {
		final ViewState viewState = mViewStates.get(holder.getViewStateID());
		final boolean hasSavedViewState = viewState != null;

		if (hasSavedViewState) {
			viewState.restore(holder);
		}
	}
}

Cannot Resolve ViewModel

Error:Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class com.thejuki.kformmaster.model.BaseFormElement, unresolved supertypes: com.github.vivchar.rendererrecyclerviewadapter.ViewModel

I am trying to use my Kotlin form library I created: https://github.com/TheJuki/KFormMaster
It implements your library to handle the different types of views. However, I cannot build my Android application that uses my library. Any ideas as to why ViewModel cannot be resolved? BaseFormElement is here: https://github.com/TheJuki/KFormMaster/blob/master/form/src/main/java/com/thejuki/kformmaster/model/BaseFormElement.kt

I added this my gradle.build:
implementation "com.thejuki:k-form-master:1.2.0"

Filter items

Sorry for asking too many questions. I need filter functionality for recycler view. Assume we have two ViewModel objects and corresponding renderers registered. When a user selects filter, I need to show only one of the ViewModels in hide the other type. How this could be done?

Unexpected Behavior Randomly Occuring

The adapter sometimes makes a fatal error for ArrayList of items, with random happening, most of the time happens in onDetach. The Error is:

FATAL EXCEPTION: main
     Process: xx.xxx.xxxx PID: 4733
     java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
     at java.util.ArrayList.remove(ArrayList.java:503)
     at com.github.vivchar.rendererrecyclerviewadapter.RendererRecyclerViewAdapter$3.run(RendererRecyclerViewAdapter.java:261)}

Code in Brief:

public void initUI(){
        mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
        mRecyclerViewAdapter.registerRenderer(new LoadMoreViewBinder(R.layout.view_holder_load_more));
        mRecyclerViewAdapter.registerRenderer(createSearchResultPeopleBinder(R.layout.view_holder_search_result_people));
        mRecyclerViewAdapter.registerRenderer(createSearchResultTickerBinder(R.layout.view_holder_search_result_ticker));
        mRecyclerViewAdapter.registerRenderer(createSearchResultPostPreviewBinder(R.layout.view_holder_search_result_post_preview));
        mRecyclerViewAdapter.enableDiffUtil();
        rcExplore.setAdapter(mRecyclerViewAdapter);
        LinearLayoutManager lm = new LinearLayoutManager(getActivity());
        rcExplore.setLayoutManager(lm);
}
            StringRequest stringRequest = new StringRequest(
                    Request.Method.GET,
                    url,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            Gson gson = new Gson();
                            ArrayList<Profile> searchResultsPeople = gson.fromJson(response, new TypeToken<List<Profile>>() {
                            }.getType());
                            mRecyclerViewAdapter.setItems(searchResultsPeople);
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.d(Util.TAG, "Explore onErrorResponse: " + error.getMessage());
                        }
                    });
            Util.getInstance().addToRequestQueue(stringRequest);
        
@NonNull
    private ViewBinder createSearchResultPeopleBinder(final int layout) {
        return new ViewBinder<>(
                layout, /* your item layout */
                Profile.class, /* your model class */
                (model, finder, payloads) -> finder
                        .setText(R.id.searchResultUsername, model.getU())
                        .setText(R.id.searchResultName, model.getN())
                        .setOnClickListener(R.id.searchResultContainer, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Intent intent = new Intent(getActivity(), ProfileViewer.class);
                                intent.putExtra("userid", model.getId());
                                intent.putExtra("username", model.getN());
                                intent.putExtra("profilepicture", model.getPp());
                                startActivity(intent);
                            }
                        })
        );
    }

How to use Glide

I'v inspected examples and found the complex models utilizing Glide. By the way RENDERER is deprecated in latest release and I can not figure out how to use Glide in BINDERS. Any help?

change composite item in parent

hello im need change parent item text in composite please help
please see attachment im need change [Mr Tahvil] TextView in parent adapter dynamic!
image
image

How to get item position after updating items

Hello and thank you for your cool library <3
i have an implement of ViewBinder and in this binder i set position into models
like this :
`public class PositionViewBinder extends ViewBinder {

public PositionViewBinder(final int layoutID,
                          @NonNull final Class<M> type,
                          @NonNull final Binder<M> binder) {
    super(layoutID, type, binder);
}

@Override
public void bindView(@NonNull final M model, @NonNull final ViewHolder viewHolder) {

    super.bindView(model, viewHolder);
    model.setPosition(viewHolder.getAdapterPosition());
}


public static class PositionViewModel implements ViewModel {
    private int position;

    public int getPosition() {
        return this.position;
    }

    void setPosition(int position) {
        this.position = position;
    }
}

}`

but i need to update this position after another item removed because the position field hold old position
how could i achieve this?

add CustomViewFinder support

For example:
we have a custom view - AvatarView which contains special method setUrl
in current implementation we should implement

mRecyclerViewAdapter.registerRenderer(new ViewBinder<>(
	R.layout.item_layout,
	SomeModel.class,
	(model, finder, payloads) -> finder
                 .find(R.id.avatarView, (ViewProvider<AvatarView>) avatarView -> {
                         avatarView.setUrl(model.getUrl());
                 })
));

ideally we should have the ability to extend ViewFinder:

mRecyclerViewAdapter.registerRenderer(new ViewBinder<SomeModel, CustomViewFinder>(
	R.layout.item_layout,
	SomeModel.class,
	(model, finder, payloads) -> finder
                 .setUrl(R.id.avatarView, model.getUrl())
));
public class CustomViewFinder extends ViewFinderImpl {

	public CustomViewFinder(final View itemView) {
		super(itemView);
	}

	@NonNull
	public CustomViewFinder setUrl(@IdRes final int ID, @NonNull final String url) {
		((AvatarView) find(ID)).setUrl(url);
		return this;
	}
}

Unable to resolve model methods ?

I'm new to this library, I tried to implement the library version 3.0.3. In my ViewRenderer, Unable to resolved the model methods like model.getText() ? Is this Issue with new version or my implementation is wrong ?

CODE

`public class DashboardFragment extends Fragment {

private DashboardViewModel dashboardViewModel;

private RendererRecyclerViewAdapter mRecyclerViewAdapter;

public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {

    dashboardViewModel = new ViewModelProvider(this).get(DashboardViewModel.class);

    View root = inflater.inflate(R.layout.fragment_dashboard, container, false);

    mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
    mRecyclerViewAdapter.registerRenderer(getYourViewBinder());
    mRecyclerViewAdapter.setItems(getSquareItems());

    final RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
    recyclerView.setAdapter(mRecyclerViewAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    return root;
}

private ViewRenderer getYourViewBinder() {
    return new ViewRenderer(
            R.layout.item_futures, /* your item layout */
            RectViewModel.class, /* your model class */
            (model, finder, payloads) -> finder
                    .setText(R.id.title, model.getText()) /* unable to resolve model methods */
                    .setText(R.id.price, model.getID())
    );
}

public static class RectViewModel implements ViewModel {

    private int mID;
    private final String mText;

    public RectViewModel(final int ID, final String text) {
        mID = ID;
        mText = text;
    }

    public int getID() {
        return mID;
    }

    public String getText() {
        return mText;
    }
}

public List<ViewModel> getSquareItems() {
    final ArrayList<ViewModel> items = new ArrayList<>();
    for (int i = 0; i < 50; i++) {
        items.add(new Indices("Hell0 ", String.valueOf(i)));
    }
    return items;
}

} `

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.