当前位置: 代码迷 >> Android >> 想传入参数,在什么地方传递,怎么保存
  详细解决方案

想传入参数,在什么地方传递,怎么保存

热度:102   发布时间:2016-05-01 21:30:21.0
想传入参数,在什么地方传递,如何保存?
我有一个类嵌套是这样的:CSurfaceView - CRectangle - CMesh - CContentReader
即CRectangle要在CSurfaceView上用到,CRecangle包含到CMesh,而CMesh包含CContentReader

其中,CContentReader要用到Context(在Activity中就是this值)读取文件。
这个就要麻烦很多了,Context要经过这么多层传到CContentReader中,
请问,Context要保存到类中,是不是在类中声明Context并在构造函数中赋值就可以了?


------解决方案--------------------
你的想法是对的:
public class CContentReader extends CMesh {

private Context context;

public CContentReader(Context context){
this.context=context;
}

}
------解决方案--------------------
CSurfaceView - CRectangle - CMesh - CContentReader
其他类需要Context么?
如果需要统一设置一个Context的构造函数
如果不需要,也可以给CContentReader设置一个Set访问器
  相关解决方案