I have a list in activity with dynamic data.When i click on a button inside list item,I want to hide any text from list item.From adapter class it can be possible to get views from custom layout but from activity how to do this?
Asked
Active
Viewed 2,528 times
3
-
1you have to make a listener and implement it on your activity. – Viks Mar 12 '18 at 11:08
-
using listener i can be able to get the position but how to get the views with respected position from adapter viewholder inside activity – Ritika Singh Mar 12 '18 at 11:12
-
You shouldn't access views from your activity.. let your adapter handle that.. use callbacks with flags and notify your adapter whenever a change is performed so That it'll update the displayed list – ColdFire Mar 12 '18 at 11:13
-
see this answer https://stackoverflow.com/questions/30284067/handle-button-click-inside-a-row-in-recyclerview#answer-37588931 – Viks Mar 12 '18 at 11:16
-
4Possible duplicate of [Handle Button click inside a row in RecyclerView](https://stackoverflow.com/questions/30284067/handle-button-click-inside-a-row-in-recyclerview) – Viks Mar 12 '18 at 11:18
-
do you want to call a method of adapter form activity? – Sanjay Kumar Mar 12 '18 at 11:19
-
i can get the position inside activity but is it possible to get views with the respective position in main activity not in adapter? – Ritika Singh Mar 12 '18 at 11:40
-
why do you want to change the visibility of adapter contents from your activity, can you explain your scenario – Navneet Krishna Mar 12 '18 at 12:13
-
i have a food list with add to cart button when food is successfully added want to hide the add to cart button and show the cart quantity – Ritika Singh Mar 12 '18 at 12:24
2 Answers
0
Just change the data of that particular position and then call YourCustomUpdateFunc
:
//Function inside your RecyclerAdapter class
public void YourCustomUpdateFunc(int pos){
notifyItemChanged(pos);
}
Then, the onBindViewHolder
function will do its work.

Adrian Mole
- 49,934
- 160
- 51
- 83

Vipin Soni
- 169
- 7
-1
First Create local Variable in adapter class as
OnCustClick mclickListner;
then in viewholder override method like
@Override
public void onClick(View v) {
if (mclickListner != null) {
mclickListner.onItemClick(v, getAdapterPosition());
}
}
after that add this methods in your adapter class
public interface OnCustClick{
void onItemClick(View view, int position);
}
public void setOnCustClick(OnCustClick mclickListner)
{
this.mclickListner = mclickListner;
}
and in activity implement interface

matin sayyad
- 575
- 3
- 10