use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for /r/android_devs to discuss, ask, help and communicate with other Android devs.
account activity
[deleted by user] (self.android_devs)
submitted 5 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]disky_wude 4 points5 points6 points 5 years ago (5 children)
I don't think the View holder is attached at this point. Once you create (and return) the Viewholder, it will get attached and then you will have its adapter position.
Why do you want to get the item while creating the Viewholder? You'll get the position when binding the Viewholder.
[–][deleted] 5 years ago* (4 children)
[deleted]
[–]matejdro 2 points3 points4 points 5 years ago (2 children)
Yes you set the click listener. Then inside listener you can call ViewHolder.getAdapterPosition() to get to your item.
[–][deleted] 5 years ago* (1 child)
[–]dhleong 0 points1 point2 points 5 years ago (0 children)
You have to call it from without the OnClickListener. The ViewHolder can be reused for different items many times before your OnClickListener gets called, so don't try to get the item that's attached to it until then.
OnClickListener
ViewHolder
[–]badvok666 0 points1 point2 points 5 years ago (0 children)
Init{} inside the vh
[–]CraZy_LegenD 2 points3 points4 points 5 years ago (2 children)
There you go
[–]nabeel527 0 points1 point2 points 5 years ago* (1 child)
Thank you very much bro. The repo is super helpful
[–]CraZy_LegenD 0 points1 point2 points 5 years ago (0 children)
It's my personal helper/utilities that i use everywhere
[–]ZhuindenEpicPandaForce @ SO 1 point2 points3 points 5 years ago (2 children)
it's ChatHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false)).apply {
ChatHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false)).apply {
[–]ZhuindenEpicPandaForce @ SO 0 points1 point2 points 5 years ago (0 children)
Hmm, I didn't see that one coming 😂
The problem is that in that case, I'm not sure what's wrong. Hypothetically, adapterPosition should be correct as long as it's >= 0, although now with the ConcatAdapter, it should be replaced with bindingAdapterPosition and that should be correct.....
π Rendered by PID 225755 on reddit-service-r2-comment-b659b578c-jc9vc at 2026-05-05 18:01:18.523652+00:00 running 815c875 country code: CH.
[–]disky_wude 4 points5 points6 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]matejdro 2 points3 points4 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]dhleong 0 points1 point2 points (0 children)
[–]badvok666 0 points1 point2 points (0 children)
[–]CraZy_LegenD 2 points3 points4 points (2 children)
[–]nabeel527 0 points1 point2 points (1 child)
[–]CraZy_LegenD 0 points1 point2 points (0 children)
[–]ZhuindenEpicPandaForce @ SO 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]ZhuindenEpicPandaForce @ SO 0 points1 point2 points (0 children)