Not sure what you are expecting to achieve. onCreateViewHolder is called one time for each object in your collection in order to bind inflate the necessary layout and find all the views. You can inflate different layout and bind different ViewHolders based of the integer:onCreateViewHolder(ViewGroup parent, int viewType)
If you have different view types you need to override the getItemViewType method that will be called with the item position so you can determine what view type you need. This method returns an int that you will receive in onCreateViewHolder.
Here is a good example:
@Override public int getItemViewType(int position) { final Object dataObj = mDataSet.get(position); if (dataObj instanceof String) { return 0; } if (dataObj instanceof User) { return 1; } } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch(viewType) { case 0: return new StringViewHolder(...); case 1: return new UserViewHolder(...); } }
I see in your code that you are sending the data in the constructor of the ViewHolder. That defeats the purpose of this class because you will have only one ViewHolder instance for an object type and it only needs to hold the layout view information so you don't need to find the views every time you need to bind an object. You actually need to use onBindViewHolder in order to bind your object, ex:
public void onBindViewHolder(UsersGroupsAdapter.ViewHolder holder, int position) { // or something similar holder.bind(mData.get(position)); }
Hope this helps.