ExpandableLayout
ExpandableLayout copied to clipboard
Recycle View scrolls slow. How to fix it ?
Hello,
I just implemented expandable layout in recycle view .
Data coming from web-service and passing array-list through adapter.
Layout row file in Nested Linear Layouts. (may be its layouts load but I tried with Constraint layout . No Effect)
I am still finding the issue !
I am replacing view during expansion and collapse item view (I already commented that code. but still my recycle view is slow )
There is no use of any image storing in itemview .
Help me to fix this issue.

for more details about question https://stackoverflow.com/questions/45790906/recycle-view-scrolls-slow-how-to-fix-it
`public class PendingOrdersAdapter extends RecyclerView.Adapter<PendingOrdersAdapter.ViewHolder> {
public LayoutInflater mInflater;
public HashSet<Integer> mExpandedPositionSet = new HashSet<>();
Context context;
ArrayList<CustomerDetails> list;
public PendingOrdersAdapter(Context context, ArrayList<CustomerDetails> list) {
this.context = context;
this.list = list;
this.mInflater = LayoutInflater.from(context);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View item = mInflater.inflate(R.layout.pending_order_item, parent, false);
return new ViewHolder(item);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.updateItem(position, holder);
holder.tvOrderNo.setText("" + list.get(position).getOrderID());
holder.tvCustomerName.setText("" + list.get(position).getCustomerName());
holder.tvTotalPrice.setText("" + list.get(position).getTotalPrice());
holder.tvCustomerContactNo.setText("" + list.get(position).getPrimaryContactNo());
holder.tvProductWeight.setText("" + list.get(position).getProductWeight());
holder.tvCustomerStatus.setText("" + list.get(position).getCustomerStatus());
holder.tvDeliveryManStatus.setText("" + list.get(position).getDeliveryManStatus());
holder.tvAddress.setText("" + list.get(position).getAddress());
holder.tvDeliveryMan.setText("" + list.get(position).getCustomerName() + " ( " + list.get(position).getPrimaryContactNo() + " ) ");
holder.tvTime.setText("" + list.get(position).getTime());
holder.tvPickUpDate.setText("" + list.get(position).getPickupDate());
holder.tvDeliveryCharge.setText("" + list.get(position).getDeliveryCharge());
/* cusLocation = list.get(position).getCusLocation();
boLocation = list.get(position).getBoLocation();*/
//Opening DialogFragment on Click Listner
holder.tvDeliveryMan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppCompatActivity activity = (AppCompatActivity) (context);
android.app.FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
android.app.Fragment prev = activity.getFragmentManager().findFragmentByTag("dvdialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
DeliveryManDetailsDialog newFragment = new DeliveryManDetailsDialog();
newFragment.show(ft, "dvdialog");
}
});
holder.tvAddress.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
//Address icon click listner right side
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (holder.tvAddress.getRight() - holder.tvAddress.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
// your action here
Intent intent = new Intent(context, RouteActivity.class);
intent.putExtra("custLat", list.get(position).getCustLatitude());
intent.putExtra("custLong", list.get(position).getCustLongitude());
intent.putExtra("boLat", list.get(position).getBoLatitude());
intent.putExtra("boLong", list.get(position).getBosLongitude());
context.startActivity(intent);
}
return true;
}
return true;
}
});
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getItemCount() {
return list.size();
}
public void registerExpand(int position, ViewHolder holder) {
if (mExpandedPositionSet.contains(position)) {
//Replacing views at runtime and arrow animation
ViewGroupUtils.replaceView(holder.timeLayout, holder.statusLayout);
holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable);
holder.ivArrow.animate().rotation(360).start();
removeExpand(position);
} else {
ViewGroupUtils.replaceView(holder.statusLayout, holder.timeLayout);
holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable_top);
holder.ivArrow.animate().rotation(180).start();
addExpand(position);
}
}
public void removeExpand(int position) {
mExpandedPositionSet.remove(position);
}
public void addExpand(int position) {
mExpandedPositionSet.add(position);
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ExpandableLayout expandableLayout;
public LinearLayout orderbox, orderbox_bottom;
public ImageView ivArrow;
public TextView tvAddress, tvOrderNo, tvCustomerName, tvTotalPrice, tvCustomerContactNo;
public TextView tvProductWeight, tvCustomerStatus, tvDeliveryManStatus;
public TextView tvDeliveryCharge, tvDeliveryMan, tvTime;
public TextView tvPickUpDate;
public LinearLayout statusLayout, statusParentLayout, timeLayout, timeParentLayout, addressLayout;
public ViewHolder(final View itemView) {
super(itemView);
expandableLayout = (ExpandableLayout) itemView.findViewById(R.id.expandable_layout);
orderbox = (LinearLayout) itemView.findViewById(R.id.orderbox);
orderbox_bottom = (LinearLayout) itemView.findViewById(R.id.orderbox_bottom);
ivArrow = (ImageView) itemView.findViewById(R.id.ivArrow);
tvOrderNo = (TextView) itemView.findViewById(R.id.tvOrderNo);
tvCustomerName = (TextView) itemView.findViewById(R.id.tvCustomerName);
tvTotalPrice = (TextView) itemView.findViewById(R.id.tvTotalPrice);
tvCustomerContactNo = (TextView) itemView.findViewById(R.id.tvCustomerContactNo);
tvProductWeight = (TextView) itemView.findViewById(R.id.tvProductWeight);
tvCustomerStatus = (TextView) itemView.findViewById(R.id.tvCustomerStatus);
tvDeliveryManStatus = (TextView) itemView.findViewById(R.id.tvDeliveryManStatus);
tvDeliveryCharge = (TextView) itemView.findViewById(R.id.tvDeliveryCharge);
tvAddress = (TextView) itemView.findViewById(R.id.tvAddress);
tvDeliveryMan = (TextView) itemView.findViewById(R.id.tvDeliveryMan);
tvTime = (TextView) itemView.findViewById(R.id.tvTime);
tvPickUpDate = (TextView) itemView.findViewById(R.id.tvPickUpDate);
statusParentLayout = (LinearLayout) itemView.findViewById(R.id.statusParentLayout);
statusLayout = (LinearLayout) itemView.findViewById(R.id.statusLayout);
timeParentLayout = (LinearLayout) itemView.findViewById(R.id.timeParentLayout);
timeLayout = (LinearLayout) itemView.findViewById(R.id.timeDateLayout);
addressLayout = (LinearLayout) itemView.findViewById(R.id.addressLayout);
}
public void updateItem(final int position, final ViewHolder holder) {
holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable_top);
holder.expandableLayout.setOnExpandListener(new ExpandableLayout.OnExpandListener() {
@Override
public void onExpand(boolean expanded) {
registerExpand(position, holder);
}
});
expandableLayout.setExpand(mExpandedPositionSet.contains(position));
}
}
}`