从Android的其他类中调用一个主类的方法 [英] Invoke a main class method from other class in Android

查看:210
本文介绍了从Android的其他类中调用一个主类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我不知道这是可能的,这样的详细信息:

So I don't know if this is possible, so in more detail:

我有我的主类公共类迈纳尔延伸活动{和其他类的一个对象 GUIManager 。从其他的我想打电话从一个方法迈纳尔

I have my main class public class MainAR extends Activity{ and an object GUIManager of other class. From that other I want to call a method from MainAR:

public class MainAR extends Activity{
    ...
    private GUIManager mGUIManager;
    ...
    mGUIManager = new GUIManager(getApplicationContext());
    ...
    public void mehtodMain(){
        ...
    }
}

,然后其他类:

public class GUIManager {
    private MainAR mainClass;

    public GUIManager(Context context){
        //mainClass = ???
        ...
    }

    private method(){
        mainClass.mehtodMain();
    }
}

但我不知道如何初始化 mainClass ...

推荐答案

提供其主类的一个实例

mGUIManager = new GUIManager(MainAR.this);

public GUIManager(MainAR mainClass){
        this.mainClass = mainClass;
    }

这篇关于从Android的其他类中调用一个主类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆