lucasr/twoway-view

I have a button in each row and want it enable click action for it as well as i have a setOnItemClickListener which is for another action

sharathyadhav1 opened this issue · 2 comments

I have a button in each row and want it enable click action for it as well as i have a setOnItemClickListener which is for another action ,kindly help

Any solution found?

Your question is: How to set the click event for each button in the item?
My answer is: You can do it like the following coding, but better to avoid or please do not update the order of the list.

TwoWayView mRecyclerView = (TwoWayView) rootView.findViewById(R.id.lstSnapShot);

final ItemClickSupport itemClick = ItemClickSupport.addTo(mRecyclerView);
itemClick.setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
         @Override
          public void onItemClick(RecyclerView parent, View child, int position, long id) {
                 // please store the data in the ArrayList, get object back with list.get(position)
                 // Suggested to do all of your action here
                Button btnClick = (Button)child.findViewById(R.id.btnClick);
                btnClick.setOnClickListener(new View.OnClickListener(){
                        @Override
                         public void onClick(View v){
                                   // If you sure to use button click, not the item click, you need to use
                                   // btnClick .setTag(position) to record which button you are
                                  //  In this method use getTag to get the position and use list.get(position)
                                  //  By the way, it is very complex if you need to add object in the front of the list
                                  //  because the position will be incorrect
                          }
                 })
            }
 });