简体   繁体   English

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

[英]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.

相关问题 如何在Android的MainActivity中调用静态方法中的内容 - How can I call what I have in Static Method from MainActivity in Android 从android中的另一个类调用MainActivity方法 - Call MainActivity method from another class in android 来自Android中另一个类的mainactivity中的调用方法 - calling method in mainactivity from another class in android 如何从另一个 class 调用 MainActivity 中的方法? - How to call a method in MainActivity from another class? 我如何从另一个 class 访问 MainActivity object - How can i access a MainActivity object from another class 如何将方法从MainActivity运行到我的值类? - How can I run method from MainActivity to my value class? 通过创建实例android从MainActivity类调用方法到另一个类 - Calling method from MainActivity class to another class by creating instance android 如何从另一个类的静态方法更改静态变量的值 - how to change the value of a static variable from a static method of another class 从另一个类调用 MainActivity 类中的方法 - Call method in MainActivity class from another class 如何从一个方法,另一个类的变量数据中读取公共静态变量并获取更新的数据 - How do I read in a public static, with variable data from a method, from another class and get updated data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM