Skip to content

Commit

Permalink
improve robustness in case items are recycled during click
Browse files Browse the repository at this point in the history
  • Loading branch information
ramack committed Dec 18, 2017
1 parent 4cd1b29 commit 374c0ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ public DetailViewHolders(@NonNull DetailRecyclerViewAdapter.SelectListener liste

@Override
public void onClick(View view) {
mListener.onDetailItemClick(getAdapterPosition());
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
mListener.onDetailItemClick(position);
}
}

@Override
public boolean onLongClick(View v) {
return mListener.onDetailItemLongClick(getAdapterPosition());
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
return mListener.onDetailItemLongClick(position);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ public int getDetailLoaderID(){

@Override
public void onClick(View view) {
mListener.onItemClick(this, getAdapterPosition(), mDiaryEntryId);
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
mListener.onItemClick(this, position, mDiaryEntryId);
}
}

@Override
public boolean onLongClick(View view) {
return mListener.onItemLongClick(this, getAdapterPosition(), mDiaryEntryId);
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
return mListener.onItemLongClick(this, position, mDiaryEntryId);
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ public SelectViewHolders(SelectRecyclerViewAdapter.SelectListener listener, View

@Override
public void onClick(View view) {
mListener.onItemClick(getAdapterPosition());
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
mListener.onItemClick(position);
}
}

@Override
public boolean onLongClick(View v) { return mListener.onItemLongClick(getAdapterPosition()); }
public boolean onLongClick(View v) {
final int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
return mListener.onItemLongClick(position);
}
return false;
}
}

0 comments on commit 374c0ec

Please sign in to comment.