Ramotion/folding-cell-android

Problem with toggle in RecyclerView.ViewHolder

willu2 opened this issue · 11 comments

I use FoldingCell with RecyclerView. When i onClick, fc is toggled. But every 9th element at the list toogled too.
How fix this?

 View_Holder(View itemView) {

            super(itemView);

            final FoldingCell fc = (FoldingCell)itemView.findViewById(R.id.folding_celll);
            fc.initialize(1000, Color.DKGRAY, 2);
            fc.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    fc.toggle(false);
                }
            });
........

👍
Can you provide complete example with RecyclerView.

`
public class BaRecyclerViewAdapter extends RecyclerView.Adapter<BaRecyclerViewAdapter.View_Holder> {

List<Bank> contents = Collections.emptyList();
Context mContext;
Bank bank;
private Typeface mTf;
public static final int TYPE_HEADER = 0;
public static final int TYPE_CELL = 1;

public BaRecyclerViewAdapter(List<Bank> contents, Context context) {
    this.contents = contents;
    this.mContext = context;
}
@Override
public int getItemViewType(int position) {
    switch (position) {
       /* case 0:
            return TYPE_HEADER;*/
        default:
            return TYPE_CELL;
    }
}

@Override
public int getItemCount() {
    return contents.size();
    // return (dataCursor == null) ? 0 : dataCursor.getCount();
}

public List<Bank> getContents() {
    return contents;
}

public boolean isHeader(int position) {
    return position == 0;
}

@Override
public long getItemId(int position) {
    return contents.get(position).getID();
}

@Override
public View_Holder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = null;

    switch (viewType) {

        case TYPE_CELL: {
            view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.list_item_card_banks, parent, false);
            View_Holder holder = new View_Holder(view);
            return new View_Holder(view) ;//{
        }
    }
    return null;
}
public void addItemAtIndex(int index, Bank bank){
    contents.add(index, bank);
    notifyDataSetChanged();
}

public void notifyDataArray(List<Bank> myList){
    Log.d("notifyData ", myList.size() + "");
    this.contents = myList;
    notifyDataSetChanged();
}

public void insert(Bank item, int position) {
    contents.add(position, item);
    notifyItemInserted(position);
}

public void remove(Bank item) {
    int position = contents.indexOf(item);
    contents.remove(position);
    notifyItemRemoved(position);
}
public void addItem(Bank item) {
    contents.add(item);
    notifyDataSetChanged();
}
public void removeAll() {
    contents.clear();
    notifyDataSetChanged();
}

public void onBindViewHolder(final View_Holder holder, final int position) {
    //  adapterCallbackListener = (AdapterCallback) mContext;
    switch (getItemViewType(position)) {
        case TYPE_HEADER:
            break;
        case TYPE_CELL:

            String heuro_br;
            String heuro_ar;
            String husd_br;
            String husd_ar;
            String hrub_br;
            String hrub_ar;

            bank = contents.get(position);

            Gson gson = new Gson();
            String json = bank.getJson_cash_data();
            BankCashNow obj = gson.fromJson(json, BankCashNow.class);

            Gson gsonh = new Gson();
            String jsonHistory = bank.getJson_cash_history();
            BankCashHistory objHistory = gsonh.fromJson(jsonHistory, BankCashHistory.class);

            heuro_ar = objHistory.getEuro_bye();

            final String[] heuro_arParts = heuro_ar.split(";");

        holder.setData(heuro_arParts);

            holder.titleFromAdress.setText(bank.getName());
            holder.titleToAdress.setText(bank.get_city()+ " " + bank.getAdress());

            Picasso.with(mContext)
                    .load(bank.getImage())
                    .error(R.drawable.noimage)
                    .into(holder.imageLogo);

            //  notifyItemInserted(position);
            notifyDataSetChanged();

            break;
    }
}
public class View_Holder extends RecyclerView.ViewHolder/* implements View.OnClickListener */{

    CardView cv;

    TextView titlePrice;
    TextView titleDate;
    TextView titleTime;

    View_Holder(View itemView) {
        super(itemView);

        cv = (CardView) itemView.findViewById(R.id.card_view_bank);

        final FoldingCell fc = (FoldingCell)itemView.findViewById(R.id.folding_celll);
        fc.initialize(1000, Color.DKGRAY, 2);
        fc.setTag(cv);

        /*cv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fc.toggle(false);
            }

        });*/
        fc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fc.toggle(false);
            }
        });

        titlePrice = (TextView) itemView.findViewById(R.id.title_price);
        titleDate = (TextView) itemView.findViewById(R.id.title_date_label);
        titleTime = (TextView) itemView.findViewById(R.id.title_time_label);

//........................
`

@willu2
Add this :

    @Override
    public void onBindViewHolder(RecyclerViewAdapter.CustomViewHolder holder, int position) {
        holder.fc.fold(true);
}

@olsynt would you mind giving an example in code because all I get is a nullpointer exception.

@willu2 You should examine a folding-cell-listview-example, take a look at FoldingCellListAdapter class and usage of registerToggle method.

I am getting :
android.view.InflateException: Binary XML file line #3: Error inflating class com.ramotion.foldingcell.FoldingCell
How can i resolve it..

I think you are inflating the wrong view or a view that does not exist.
Kindly send a code sample of what you are doing.

I resolve this problem can you tell me how can implement SearchView in FoldingCell library ?

@willu2 @geekonjava how do you resolve this? I am having the same problem

@oleg-vasiliev I solved with your registerToggle method in a normal adapter, but I would like to implement it in my FastAdapter, can you help me please?

I implemented it, but the problem now is if scroll down until the item is out of my screen in the state unfolded and I come back to see it again unfolded, it is folded.