Skip to content Skip to sidebar Skip to footer

Calling A Method From A Different Class That Uses Variables Outside The Method

I have a problem. I have a method in a class like this: public void UpdateActionBar(int CurrentFragmentNum) { if (CurrentFragmentNum == 1) { btnBack.Visibility = Vi

Solution 1:

you could make your ActionBar_Setup singleton:

publicclassActionBar_Setup : Android.Support.V4.App.Fragment
 {

    publicstatic ActionBar_Setup Instance;
    publicstatic ActionBar_Setup NewInstance()
    {
        if (Instance== null)
        {
            Instance= new ActionBar_Setup();

        }

        return Instance;
    }
    ...
}

then when you create the ActionBar_Setup like this:

ActionBar_SetupfActionBarSetup= ActionBar_Setup.NewInstance();

finally call UpdateActionBar method in other class like this:

ActionBar_Setup.Instance.UpdateActionBar(3);

Solution 2:

you can pass parameters to your button events from the view as a GET or POST values on the button and assign the values to your method directly from the views

Solution 3:

Theyre multiple ways to achieve what you want as per what Ahmed Moawad says. Another possible solution would be to add a btnBack and a btnNext field in the class. Then assign the values to the fields. Once you execute the method. You should be able to grab the fields within the calling method.

I would say seperate the UpdateActionBar method from the form actions. So you'll have your UpdateActionBar in a seperate class as you do. But your btnBack and btnNext fields should probably be named some thing else. Then within the calling method assign the results of your fields to btnNext and btnBack.

Post a Comment for "Calling A Method From A Different Class That Uses Variables Outside The Method"