[英]Android - How can i sync a method in mainActivity with a static boolean variable from another class?
I have a method in the mainActivity
, this method Refresh my RecyclerView
. 我在
mainActivity
有一个方法,该方法刷新我的RecyclerView
。 I want sync that method to a static boolean
variable and can be Called for every change of that boolean
variable. 我想将该方法同步到
static boolean
变量,并且可以对该boolean
变量的每次更改进行调用。
here's my Method: 这是我的方法:
public void RefreshView() {
recyclerView = (RecyclerView) findViewById(R.id.recyclerMainView);
recyclerAdapter = new RecyclerAdapter(context, getData());
recyclerView.setAdapter(recyclerAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
}
Pass the context of MainActivity to your class/fragment in the class constructor and use it call the MainActivity methods whenever your boolean variable is changed 将 MainActivity 的上下文传递给类构造函数中的类/片段,并在更改布尔变量时使用它调用MainActivity方法
if(booleanChanged){
((MainActivity) context).RefreshView();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.