0
Guys, I’m new in Android development and I came across a line of code like this:
int animar = visivel ? android.R.anim.fade_out : android.R.anim.fade_in;
Animation a = AnimationUtils.loadAnimation(this, anim);
animation(a);
My only question is: What that line below does?
visivel ? android.R.anim.fade_out : android.R.anim.fade_in
http://answall.com/search?q=ternario, briefly is a compact if/Else, if there is a value in
visivel
,animar
will receive the value after the question of the opposite will receive the value after the two points. if something ? true condition : false condition.– rray
This is a ternary operator, it is similar to an if.
visivel
is the condition, that when true, applies the entire constant ofandroid.R.anim.fade_out
the variableanimar
, if false, apply the constantandroid.R.anim.fade_in;
instead.– user28595
It would be nice for other people to vote to close as a duplicate of other questions on the subject, so there is a multiple reference to the various questions on the subject.
– Maniero
I’m sorry, but since I didn’t understand, you can open a vote, if I can, I’ll vote for you.
– Leonan Leonardo