android 非activity中调用mainactivity中的控件等

非activity中调用MainActivity中的非静态方法、布局或控件、接口:

参数传递:传 this。

https://bbs.csdn.net/topics/360023885

public class MainActivity extends Activity
{
   ……
   public void anotherClass()
   {
      AnotherClass activity = new AnotherClass(this);
   }
}
 
public class AnotherClass
{
    private MainActivity activity;
    public AnotherClass(MainActivity activity)
    {
       this.activity = activity;
    }
}

 

你可能感兴趣的:(android)