V
V
Vladislav Bukach2021-10-24 12:25:15
Java
Vladislav Bukach, 2021-10-24 12:25:15

How to change a variable in the class of another file by clicking on the button?

Here is the code from the first file

@Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        sub1 = (Button) view.findViewById(R.id.sub_tav);
        sub2 = (Button) view.findViewById(R.id.sub_kop);

     
        sub1.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(),"Подписка на магаз1 офромлена успешно!",Toast.LENGTH_SHORT).show();
               App.getInstance(true);

            }
        });

And here is such a class in another file

import android.app.Application;

public class App extends Application {
    public static boolean isActive = false;

    public static boolean getInstance(boolean b) {
        b = false;
        return b;

    }

    public boolean getActive(boolean b) {
        return isActive;
    }

    public void setisActive(boolean _isActive) {
        this.isActive= _isActive;
    }

}

So that when you click on the button in the second file, the value of the boolean variable b getInstance changes from false to true

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fxmike, 2021-10-25
@fxmike

What does this method do? How is the b parameter related to isActive?
public boolean getActive(boolean b) {
return isActive;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question