]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java
guard against a race condition when the transaction list is reduced while the scrolle...
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / TransactionListAdapter.java
index 2e52093d57669744a7ae9fc9e52f8266ca2d3a94..559a247beb3b495223d5d68921a3c6e57ecb9fd8 100644 (file)
@@ -48,6 +48,12 @@ class TransactionListAdapter
     }
 
     public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) {
+        // in a race when transaction list is reduced, but the model hasn't been notified yet
+        // the view will disappear when the notifications reaches the model, so by simply omitting
+        // the out-of-range get() call nothing bad happens - just a to-be-deleted view remains
+        // a bit longer
+        if (position >= transactions.size()) return;
+
         LedgerTransaction tr = transactions.get(position);
         Context ctx = holder.row.getContext();
 
@@ -125,7 +131,7 @@ class TransactionListAdapter
         ConstraintLayout row;
         public TransactionRowHolder(@NonNull View itemView) {
             super(itemView);
-            this.row = (ConstraintLayout) itemView;
+            this.row = itemView.findViewById(R.id.transaction_row);
             this.tvDescription = itemView.findViewById(R.id.transaction_row_description);
             this.tvDate = itemView.findViewById(R.id.transaction_row_date);
             this.tableAccounts = itemView.findViewById(R.id.transaction_row_acc_amounts);