h6ah4i / android-advancedrecyclerview

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)
https://advancedrecyclerview.h6ah4i.com/
Apache License 2.0
5.32k stars 862 forks source link

Expandable view not inflating. #473

Closed Devspm closed 5 years ago

Devspm commented 5 years ago

Hi , Thanks for the awesome library. I'm using this library for creating expandable recyclerview. I've used this library before and it worked pretty well.But this time I couldn't get it to inflate, and i couldn't find the problem.As far as I know ,nothing happens after I set the adapter for the recyclerview.You can find my code below.

setting the group and child objects with Ids.

List<ChannelCategories> channelCategories = new ArrayList<>();
                       for (int k = 0; k < channelCats.length(); k++) {
                            List<Channels> channelsList = new ArrayList<>();
                              for (int p = 0; p < array.length(); p++) {
                              String channelId = thatChannelCatId.getString(p);
                              String dth_channel_name = channelDetails.getString(channelId);
                              channelsList.add(new Channels(p, dth_channel_name, dth_channel_cat_id));
                          }
                          channelCategories.add(new ChannelCategories(k, dth_channel_cat_name, channelsList));
                    }

Setting the adapter. channelRecycler.setAdapter(new ChannelCategoriesAdapter(channelCategories));

Adapter

public class ChannelCategoriesAdapter extends AbstractExpandableItemAdapter<ChannelCategoriesAdapter.GroupViewH, ChannelCategoriesAdapter.ChildViewH> {

    private List<ChannelCategories> channelCategories;

    static class GroupViewH extends AbstractExpandableItemViewHolder {

        @BindView(R.id.channelArrow)
        AppCompatImageView channelArrow;
        @BindView(R.id.catTitle)
        TextView catTitle;

        GroupViewH(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    static class ChildViewH extends AbstractExpandableItemViewHolder {

        @BindView(R.id.channelName)
        TextView channelName;

        ChildViewH(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }

    public ChannelCategoriesAdapter(List<ChannelCategories> channelCategories) {
        this.channelCategories = channelCategories;
        setHasStableIds(true);
    }

    @Override
    public GroupViewH onCreateGroupViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.dth_package_channel_group, parent, false);
        return new GroupViewH(view);
    }

    @Override
    public ChildViewH onCreateChildViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.dth_package_channel_child, parent, false);
        return new ChildViewH(view);
    }

    @Override
    public void onBindGroupViewHolder(GroupViewH holder, int groupPosition, int viewType) {
        holder.catTitle.setText(String.format("%s,(%s)", channelCategories.get(groupPosition).getDthChannelCatName()
                , channelCategories.get(groupPosition).getChannelsList().size()));
    }

    @Override
    public void onBindChildViewHolder(ChildViewH holder, int groupPosition, int childPosition, int viewType) {
        holder.channelName.setText(channelCategories.get(groupPosition).getChannelsList().get(childPosition).getChannelName());
    }

    @Override
    public boolean onCheckCanExpandOrCollapseGroup(GroupViewH holder, int groupPosition, int x, int y, boolean expand) {
        if (expand) {
            holder.channelArrow.setImageDrawable(ContextCompat.getDrawable(holder.channelArrow.getContext(), R.drawable.ic_up_arrow_new_gray));
        } else {
            holder.channelArrow.setImageDrawable(ContextCompat.getDrawable(holder.channelArrow.getContext(), R.drawable.ic_arrow_down_gray));
        }
        return channelCategories.get(groupPosition).getChannelsList().size() > 0;
    }

    @Override
    public int getGroupCount() {
        return channelCategories.size();
    }

    @Override
    public int getChildCount(int groupPosition) {
        return channelCategories.get(groupPosition).getChannelsList().size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return channelCategories.get(groupPosition).getId();
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return channelCategories.get(groupPosition).getChannelsList().get(childPosition).getId();
    }
}

Xml

<android.support.v7.widget.RecyclerView
                android:id="@+id/channelRecycler"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:orientation="vertical"
                app:layoutManager="android.support.v7.widget.LinearLayoutManager"
                app:layout_constraintEnd_toEndOf="@id/guideline15"
                app:layout_constraintStart_toStartOf="@id/guideline14"
                app:layout_constraintTop_toBottomOf="@id/chaCatTextview" />
Devspm commented 5 years ago

Found it, forgot about few of the most important lines.