I have a RecyclerView
where each ViewHolder
contains a nested Linear Layout with some TextViews
and a button. (The button is a Facebook ShareButton
but I see the same behavior with a regular Button
as well.) When I click the ShareButton
once, nothing happens. When I click it again, it is successful.
Some clues:
- Other answers on stackoverflow say to set the button's
focusable
andfocusableInTouchMode
to false -- this has not made a difference in my case. - By using some print statements, I see that the first time I click the button, it calls
bind
again on eachViewHolder
. - If I minimize the app, then pull it up again, the first click works.
Relevant bind
code below:
public void bind(Plaque plaque) {
Log.d(TAG, "BINDING!");
LinearLayout layout = (LinearLayout) itemView;
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache();
Bitmap map = layout.getDrawingCache();
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(map)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
mShareButton.setShareContent(content);
}
When I click mShareButton
the first time, it just recalls this code (triggering the print statement at the top). When I click it again, it sends the content to Facebook, as it's supposed to do.
Any ideas how to get it to work the first time, without calling bind
again?