lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

RecyclerView$LayoutParams cannot be cast to SpannableGridLayoutManager$LayoutParams #202

Closed bpillon closed 9 years ago

bpillon commented 9 years ago

Hi,

I'm trying to make a custom display on my grid and for that, I want to use SpannableGridLayoutManager's LayoutParams.

I have something like that :

public void onBindViewHolder(CategoryViewHolder holder, int position) {
    Category category = mItems.get(position);
    holder.name.setText(category.name);

    final View itemView = holder.itemView;

    final int itemId = position;

    final SpannableGridLayoutManager.LayoutParams lp =
            (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams();

    final int span1 = (itemId == 0 || itemId == 3 ? 2 : 1);
    final int span2 = (itemId == 0 ? 2 : (itemId == 3 ? 3 : 1));

    final int colSpan = (true ? span2 : span1);
    final int rowSpan = (true ? span1 : span2);

    if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) {
        lp.rowSpan = rowSpan;
        lp.colSpan = colSpan;
        itemView.setLayoutParams(lp);
    }
}

And i obtain the following error : java.lang.ClassCastException: android.support.v7.widget.RecyclerView$LayoutParams cannot be cast to org.lucasr.twowayview.widget.SpannableGridLayoutManager$LayoutParams

Do you see any explanation for this error ? Thanks

bpillon commented 9 years ago

I replaced my adapter by yours in samples and it's worked... After comparison I don't find any difference but it works.

leeheungsoo commented 7 years ago

it's to late.... i show same issue.

member_list.setLayoutManager(new SpannableGridLayoutManager(getActivity()));

i try add layoutmanger to twowayview, then it's work