Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ShipmentsAdaptor extends ArrayAdapter<Shipment> {
- private RealmResults<Shipment> dataSet;
- Context mContext;
- // View lookup cache
- private static class ViewHolder {
- TextView stockItemId;
- TextView technicianName;
- TextView shipmentDate;
- }
- public ShipmentsAdaptor(RealmResults<Shipment> data, Context context){
- super(context, R.layout.shipments_out_row_item, data);
- this.dataSet = data;
- this.mContext = context;
- }
- private int lastPosition = -1;
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // Get the data item for this position
- Shipment shipment = getItem(position);
- // Check if an existing view is being reused, otherwise inflate the view
- ViewHolder viewHolder; // view lookup cache stored in tag
- final View result;
- if (convertView == null) {
- viewHolder = new ViewHolder();
- LayoutInflater inflater = LayoutInflater.from(getContext());
- convertView = inflater.inflate(R.layout.shipments_out_row_item, parent, false);
- viewHolder.stockItemId = convertView.findViewById(R.id.stockItemId);
- viewHolder.technicianName = convertView.findViewById(R.id.technicianName);
- viewHolder.shipmentDate = convertView.findViewById(R.id.shipmentDate);
- result = convertView;
- convertView.setTag(viewHolder);
- } else {
- viewHolder = (ViewHolder) convertView.getTag();
- result=convertView;
- }
- lastPosition = position;
- if(shipment != null){
- viewHolder.stockItemId.setText(String.valueOf(shipment.id));
- if(shipment.technician != null){
- viewHolder.technicianName.setText(shipment.technician.name);
- }
- viewHolder.shipmentDate.setText(shipment.shippingDate);
- }
- // Return the completed view to render on screen
- return convertView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement