Search code examples
javaandroidbuttonadaptercardview

how to set different onclick listener for each button populated by a recyclerview


I was modifying this code > https://rubensousa.github.io/2016/08/viewpagercards to fit my own app but as you can find from the source code there is no method to handle onclick event for each buttons, My plan is to add different intent for each button clicked on the cardviews so please help me out I'm a noob/beginner to android and java


Solution

  • You can try it by using Switch statement based on positions in onBindViewHolder. For example:

    Switch(position){
    case 0:
    //Button No.1
    break;
    case 1:
    //Button No.2
    break;
    .....
    }