开发者

passing variables to an outside class

I split my inner Vi开发者_C百科ew class from my Main class into its own file. In my main class, I have the view set as an onTouchListener which records user movement into a matrix so it can translate and scale the view. After separating it everything works but im unsure how to pass the matrix to the View for onDraw to update. Any suggestions? Thanks


I can think of two ways to do this:

You could create a variable for your matrix in your View class and a method that accepts a matrix as argument and that updates the var with this matrix value. Then you can call this method from your main Activity before calling your onDraw() method, which can then use this internal var for its calculations and so on.

An alternative would be for your matrix var in your main class to be static so you can call it from your View without needing to have an instance of your main class accessible within your View class.

The latter method is the best as it doesn't require your app to maintain two vars with essentially the same value but the former method might be easier to implement, depending on how your matrix is calculated/implemented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜