How to refresh a view in main activity from an adapter?

后端 未结 4 626
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 12:03

I have a graph in main activity also I have a recycler view in main activity. Custom adapter is used for recyclerview. I have a check box and swipe layout in list item layout. i

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 12:52

    You can change a view from the context of an adapter like this : cast context to activity. use findviewbyid method to find the view you want. initiliaze it to a variable.

    View v = ((Activity)getContext()).findViewById(WHATEVER_VIEW_COMPONENT_YOU_WANT);
    

    change the variable as you want. note. Don't forget to use the type of view that you want and cast the findview method to it.

    If you want to call a method just cast the context to MainActivity and call it.

提交回复
热议问题