繁体   English   中英

Android-如何将mainActivity中的方法与另一个类的静态布尔变量同步?

[英]Android - How can i sync a method in mainActivity with a static boolean variable from another class?

我在mainActivity有一个方法,该方法刷新我的RecyclerView 我想将该方法同步到static boolean变量,并且可以对该boolean变量的每次更改进行调用。

这是我的方法:

public void RefreshView() {

    recyclerView = (RecyclerView) findViewById(R.id.recyclerMainView);
    recyclerAdapter = new RecyclerAdapter(context, getData());
    recyclerView.setAdapter(recyclerAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));

}

MainActivity 的上下文传递给类构造函数中的类/片段,并在更改布尔变量时使用它调用MainActivity方法

if(booleanChanged){
((MainActivity) context).RefreshView();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM