FastAdapter
FastAdapter copied to clipboard
Need the clarification of the process about the click in clickeventhook
Hello sir ,
Please anybody can confirm the process i am doing in the multiple button click in the viewholder button is correct or not
likeList_adapter.withItemEvent(new ClickEventHook<LikeList_Adapter>() {
@Override
public void onClick(View v, int position, FastAdapter<LikeList_Adapter> fastAdapter, LikeList_Adapter item) {
if (v.getId()==R.id.likebutton){
Toast.makeText(v.getContext(), "Like Button clicked", Toast.LENGTH_SHORT).show();
}else if (v.getId()==R.id.unlikebutton){
Toast.makeText(v.getContext(), "UnLike Button clicked", Toast.LENGTH_SHORT).show();
}
}
@Nullable
@Override
public List<View> onBindMany(@NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof LikeList_Adapter.LikeList_ViewHolder){
return ClickListenerHelper.toList(((LikeList_Adapter.LikeList_ViewHolder) viewHolder).itemView.findViewById(R.id.likebutton),((LikeList_Adapter.LikeList_ViewHolder) viewHolder).itemView.findViewById(R.id.unlikebutton));
}
return super.onBindMany(viewHolder);
}
})
```;
@veeranath for 2 different actions you should just define 2 event hooks. so you will add one eventhook with the like logic, and one with the unlike logic.
The bindMany should be used if you have the same logic for these 2 clickable views
Is this right sir? but the difference between them sir
likeList_adapter.withItemEvent(new ClickEventHook<LikeList_Adapter>() {
@Override
public void onClick(View v, int position, FastAdapter<LikeList_Adapter> fastAdapter, LikeList_Adapter item) {
Toast.makeText(Like_List.this,"Like Button", Toast.LENGTH_SHORT).show();
}
@Nullable
@Override
public View onBind(@NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof LikeList_Adapter.LikeList_ViewHolder){
return ((LikeList_Adapter.LikeList_ViewHolder)viewHolder).itemView.findViewById(R.id.likebutton);
}
return null;
}
});
likeList_adapter.withItemEvent(new ClickEventHook<LikeList_Adapter>() {
@Override
public void onClick(View v, int position, FastAdapter<LikeList_Adapter> fastAdapter, LikeList_Adapter item) {
Toast.makeText(Like_List.this,"Unlike Button", Toast.LENGTH_SHORT).show();
}
@Nullable
@Override
public View onBind(@NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof LikeList_Adapter.LikeList_ViewHolder){
return ((LikeList_Adapter.LikeList_ViewHolder)viewHolder).itemView.findViewById(R.id.unlikebutton);
}
return null;
}
});
@veeranath that's correct now.
thank u sir