Last active
September 18, 2019 12:45
-
-
Save theonlyanil/14c2224665ebe10bf9423b339f18b87f to your computer and use it in GitHub Desktop.
How to implement Item Click on RecyclerView (Easiest Approach)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Changes start from here... */ | |
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener | |
{ | |
// each data item is just a string in this case | |
public TextView mTextView; | |
public ViewHolder(View itemView) { | |
super(itemView); | |
itemView.setOnClickListener(this); | |
mTextView = itemView.findViewById(R.id.textView); | |
} | |
@Override | |
public void onClick(View view) | |
{ | |
// get the position on recyclerview. | |
int pos = getLayoutPosition(); | |
SingleItemClick(pos); // click on recyclerview item. | |
} | |
} | |
/* Changes End Here */ |
@nvinai It's a custom function which takes integer pos and passes to other variables. Useful if you have many lines of code in onClick, else you can write your code just here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the function for SingleItemClick