Git Product home page Git Product logo

Comments (8)

cyberrob-zz avatar cyberrob-zz commented on August 20, 2024 1

getItemCount() in ExpandableRecyclerViewAdapter:

/**
   * @return the number of group and child objects currently expanded
   * @see ExpandableList#getVisibleItemCount()
   */
  @Override
  public int getItemCount() {
    return expandableList.getVisibleItemCount();
  }

it returns size of only visibleItemCount(). So if you overrides parent method, you might try to follow the logics of how it's calculated.

from expandable-recycler-view.

rajsuvariya avatar rajsuvariya commented on August 20, 2024

Hi please upload your code on StackOverflow and post a link here, I have used this library and it works perfectly fine so there must be some problem with your code.

from expandable-recycler-view.

rahulyadav7001 avatar rahulyadav7001 commented on August 20, 2024

Hi @mandybess ,
I'm also getting this same problem what @sevaktahmazyan got
FATAL EXCEPTION: mainProcess: com.thoughtbot.expandablerecyclerview.sample, PID: 2172 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder {2dbff790 position=7 id=-1, oldPos=5, pLpos:5 scrap [attachedScrap] tmpDetached no parent}

@mandybess request you to please help us.

from expandable-recycler-view.

james-murphy-dev avatar james-murphy-dev commented on August 20, 2024

@rahulyadav7001 @sevaktahmazyan Same problem here :-/

from expandable-recycler-view.

rajsuvariya avatar rajsuvariya commented on August 20, 2024

@rahulyadav7001 @jamesmurphyftw please upload your code here

from expandable-recycler-view.

james-murphy-dev avatar james-murphy-dev commented on August 20, 2024

@rajsuvariya

Activity.class:

`//...
templateFragment.setAdapter(templateGroupList, kinveyClient);
//...

TemplateFragment.class

//...
public void setAdapter(List<TemplateGroup> data, Client kinveyClient) {
        progressBar.setVisibility(View.GONE);
        mList.setVisibility(View.VISIBLE);
        final TemplateListAdapter adapter = new TemplateListAdapter(data, this.getActivity(), kinveyClient);
        mLayoutManager = new WrapContentLinearLayoutManager(getContext());
        mList.setAdapter(adapter);
        mList.setLayoutManager(mLayoutManager);
        mList.setHasFixedSize(true);
    }
//...

TemplateListAdapter.class

public class TemplateListAdapter extends ExpandableRecyclerViewAdapter<FormDataCategoryViewHolder, TemplateActionsViewHolder>{
    private List<TemplateGroup> mDataset;
    private Context context;
    private DataStore<KCTemplateBean> templateData;
    private LayoutInflater mInflater;

    // Provide a suitable constructor (depends on the kind of dataset)
    public TemplateListAdapter(List<TemplateGroup> myDataset, Context ctx, Client kinveyClient) {
        super(myDataset);
        if (ctx!=null){

            context = ctx;
            mInflater = LayoutInflater.from(context);
            mDataset = myDataset;
            templateData = DataStore.collection(AppProperties.KINVEY_COLLECTION_TEMPLATES, KCTemplateBean.class, StoreType.SYNC, kinveyClient);
        }
    }

    @Override
    public FormDataCategoryViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType){
        View view = mInflater.inflate(R.layout.list_item_category, parent, false);
        return new FormDataCategoryViewHolder(view);
    }

    @Override
    public TemplateActionsViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType){
        View view = mInflater.inflate(R.layout.template_actions, parent, false);
        return new TemplateActionsViewHolder(view);
    }

    @Override
    public void onBindGroupViewHolder(FormDataCategoryViewHolder holder, int flatPostition, ExpandableGroup group){
        holder.setFormDataCategoryTitle(group);
    }

    @Override
    public void onBindChildViewHolder(TemplateActionsViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex){
        final KCTemplateBean templateBean = (KCTemplateBean) group.getItems().get(childIndex);
        holder.setTemplateActions(context, templateBean, templateData);
    }
    @Override
    public boolean onGroupClick(int flatPosition){

        return super.onGroupClick(flatPosition);
    }
    // Return the size of your dataset (invoked by the layout manager)
    @Override
    public int getItemCount() {
        return mDataset.size();
    }
}

TemplateActionsViewHolder.class

public class TemplateActionsViewHolder extends ChildViewHolder implements View.OnClickListener {
    private Button previewButton, purchaseButton;
    private KCTemplateBean templateBean;
    private DataStore<KCTemplateBean> templateData;
    private Context mContext;

    public TemplateActionsViewHolder(View itemView){
        super(itemView);
        previewButton = (Button)itemView.findViewById(R.id.previewButton);
        purchaseButton = (Button)itemView.findViewById(R.id.purchaseButton);
    }

    public void setTemplateActions(final Context context, final KCTemplateBean template, final DataStore<KCTemplateBean> templateData){
        this.templateBean = template;
        this.templateData = templateData;
        mContext = context;
        previewButton.setOnClickListener(this);
        purchaseButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.previewButton:
                //preview
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.purchaseButton:
//purchase
                break;
        }
    }
}

I should also mention that when any of the parent groups are expanded, the last parent disappears from the list until they are all collapsed. Each parent group has exactly one child. have another ExpandableRecyclerView that's working mostly fine, but it has a different child view holder and fixed number of parent view holders, where this one is variable.

from expandable-recycler-view.

james-murphy-dev avatar james-murphy-dev commented on August 20, 2024

@rajsuvariya Any advice?

from expandable-recycler-view.

prashant9934 avatar prashant9934 commented on August 20, 2024

Please extend a LinearLayoutManager and put an ExceptionHandler and use the CustomLinearLayout manager

public class CustomLinearLayoutManager extends LinearLayoutManager {
    public LinearLayoutManagerWrapper(Context context) {
        super(context);
    }

    public LinearLayoutManagerWrapper(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }
    // java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        try {
            super.onLayoutChildren(recycler, state);
        } catch (IndexOutOfBoundsException e) {

        }
    }
}```

This will fix your issue

from expandable-recycler-view.

Related Issues (20)

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.