I have a ViewHolder Class.
class VHHeader extends RecyclerView.ViewHolder{
TextView txtTitle;
RecyclerView recyclerView;
public VHHeader(View itemView) {
super(itemView);
this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader);
this.recyclerView =(RecyclerView)itemView.findViewById(R.id.recyclerView);
}
}
Now I want to access this View Holders recycler view in some different method in same adapter class .
Public void useRecyclerView(){
}
How to use the element of View Holder in this method.
I think you want to use your view holder elements in some of the methods with in same adapter. so for that you need to pass the view holder and position in the function in which you can use your view holder elements.
Example.
@Override
public void onBindViewHolder(final AdapterName.ViewHolder holder, final int position) {
holder.elementname.setText(arrayList.get(position).getYourMethodName());
holder.elementname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
yourMethodName(holder,position);
}
});
}
//and in that method you can use your view holder elements.
private void yourMethodName(final AdapterName.ViewHolder holder,final int position)
{
holder.elementname.setText(arrayList.get(position).getYourMethodName());
}
//This way you can use your elements
As i understand, you want to make some changes on item click of recyclerview. You don't need to store your viewholder. You can set clicklistener on adapter's onBindViewHolder method like:
@Override
public void onBindViewHolder(final VHHeader holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do your operations here like
holder.txtTitle.setText("new title");
}
});
}
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With