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

后端 未结 4 619
隐瞒了意图╮
隐瞒了意图╮ 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:50

    Create a interface that implement Activity, Main activity in your case and override method and perform operation.

    //Interface
    
    public interface OnRefreshViewListner{
    
      public void refreshView();
    
    }
    
    
    //Main Activity
     MainActivity extends Activity implements OnRefreshViewListner
    {
    
      //Other methods
    
      @Override
      public void refreshView(){
    
        // write refresh code here
    
     }
    
    }
    
    
    //Initialize Interface in adapter constructor
    
    public class YourAdapter extends BaseAdapter {
    
     private OnRefreshViewListner mRefreshListner;
     public YourAdapter (Context context) {
           mRefreshListner = (OnRefreshViewListner)context; 
        }
    
        //call MainActivity method
        mRefreshListner.refreshView();
    }
    

提交回复
热议问题