FastAdapter icon indicating copy to clipboard operation
FastAdapter copied to clipboard

Need the clarification of the process about the click in clickeventhook

Open veeranath opened this issue 9 years ago • 4 comments

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 avatar Dec 27 '16 07:12 veeranath

@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

mikepenz avatar Dec 27 '16 07:12 mikepenz

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 avatar Dec 27 '16 08:12 veeranath

@veeranath that's correct now.

mikepenz avatar Dec 27 '16 08:12 mikepenz

thank u sir

veeranath avatar Dec 27 '16 08:12 veeranath