Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialvalkrye wing
71 Pointsalternative OnClick in RecyclerView, please give your argumentation
instead of writing lots of line for onclick callback to the activity, in the fragment, in the adapter,
i think using onClick for the holder is much way better, please give your comment.
Fragment _fragment;
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
((CViewHolderRecipe) holder).onBind(position);
((CViewHolderRecipe) holder).itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//
// 1st method, direct access to the holder
// ((CViewHolderRecipe) holder)._textRecipe.setText("hello");
//2nd method using the View v
//TextView textRecipe = (TextView) v.findViewById(R.id.itemText);
//textRecipe.setText("hello");
//for fragment
_fragment.getFragmentManager().beginTransaction().replace(R.id.Holder, new FragmentCustom()).commit()
}
});
}
rajan lagah
2,539 Pointsrajan lagah
2,539 Pointsthanks sir!!! my on click was not working and now use this way and finally it display toast on click
thanku :-)