Android: Trigger redraw after a colour change

血红的双手。 提交于 2019-12-10 22:23:39

问题


I am currently working on a Connect four game.

My game works by the user pressing the 'New game' button. This then draws 42 (7*6) green circles to screen. These circles are used to represent holes on the connect four board i.e. green circles currently do not contain a player's token/counter

At this moment in time I am working on adding the tokens/counters. I have got code working (to a certain point) that enables the user to pick a column. Using log.d() It seems that I am successful changing the colour value of the gaps. My problem is that I do not know how to send this changing in colour to the View i.e. so the gap actually changes from green to red (player's token colour).

How can I send a request to the View so the gap is re-drawn?

N.B. Sorry for the lack of code but it is currently messy and not fully working. The View is controlled by a ConnectFourView.java (View), the game screen is Board.java (Model) and the code that works out which column has been selected Gaps.java (controller)


回答1:


Just call invalidate() on your view and it will be redrawn



来源:https://stackoverflow.com/questions/14172914/android-trigger-redraw-after-a-colour-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!