0
Is this code right? It's a code from Android studio, i don't understand what's the function of activeplayer=1????
public class MainActivity extends ActionBarActivity { // 0 = yellow, 1 = red int activePlayer = 0; public void dropIn(View view) { ImageView counter = (ImageView) view; counter.setTranslationY(-1000f); if (activePlayer == 0) { counter.setImageResource(R.drawable.yellow); activePlayer = 1; } else { counter.setImageResource(R.drawable.red); activePlayer = 0; } }
7 ответов
+ 6
Well, I think the code is correct. There is a button or so whose onclick() maybe set as the dropIn() function. That moves the ImageView down and changes its color to yellow or red depending on the integer variable 'activePlayer'.
+ 6
Can you tell what exactly should be done by this code?
+ 5
That's it. When user touches for the first time, 'activePlayer' is 0 meaning yellow color is set and 'activePlayer' is set to 1. For the next touch, 'activePlayer' is 1 meaning red color is set and 'activePlayer' is again set to 0.
0
but what's the use of 1 , I am writing same code but ain't getting same results as instructor 😥
yeah onclick is set to dropIn
0
it's a tic tac toe game's code , when a user touch screen it should show yellow image then red image then yellow , like that
but what my code is doing, showing only yellow images , no red image
0
yeah that's correct only problem is when I enter this code on my Android studio only yellow colour is showing no red color at all
0
can someone tell me?