I am calling a onClickListener() of textView which is inside my cardview, and showing the dialog fragment which has a ADD(positive) and Cancel(negative) buttons.
Everything is working fine and as I wanted. But problem is that when I press Cancel button and scroll the recyclerview it throws "java.lang.IndexOutOfBoundsException: Inconsistency detected." exception.
I don't know where the problem is I tried notifyDataSetChanged() but it caused another problem. I have been trying again and again but the problem still exists.
Here is the onBindVIewHolder() code.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
//GETTING THE EACH OBJECT OF EXPENSEDATA [CONTAINING EACH ROW FROM DB]
FROM ARRAYLIST
ExpenseData ed = expenseDataArrayList.get(position);
//GETTING VALUE OF CARDVIEW FROM ABOVE CONSTRUCTOR AND SETTING IT TO
cardView
CardView cardView = holder.cardView;
TextView edit = (TextView)cardView.findViewById(R.id.edit);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = holder.getAdapterPosition();
System.out.println("Position = "+pos);
eddd = expenseDataArrayList.remove(pos);
expName = eddd.getExpName(); expType = eddd.getExpType(); expAmt = eddd.getExpAmt();
EditAddExpenseDialog editAddExpenseDialog = new EditAddExpenseDialog();
Bundle args = new Bundle();
args.putString("expName",expName);
args.putString("expType",expType);
args.putDouble("expAmt",expAmt);
editAddExpenseDialog.setArguments(args);
editAddExpenseDialog.show(((Activity)context).getFragmentManager(), "update ima");
}
});
}