将整数值从活动类传递给非活动类

时间:2017-12-14 05:12:47

标签: java android

我是android studio的新手。我需要将活动类中的整数值传递给android studio中的非活动类。

活动类:

public class Main2Activity extends Activity {
    // enter code here
 }

非活动类:

public class GameView extends View {
  public GameView(Context context, Maze maze){                                           }
}

1 个答案:

答案 0 :(得分:0)

for simplest, use constructer
like:

public class Main2Activity extends Activity 
{

 int x=5;
 GameView view =new GameView(x)

 }


public class GameView extends View {
int y;     
GameView(int y){
this.y=y;
}
//your values has been passed

}