What does the code line "var ? int : int"

Asked

Viewed 47 times

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

  • 2

    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.

  • This is a ternary operator, it is similar to an if.visivel is the condition, that when true, applies the entire constant of android.R.anim.fade_out the variable animar, if false, apply the constant android.R.anim.fade_in; instead.

  • 2

    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.

  • I’m sorry, but since I didn’t understand, you can open a vote, if I can, I’ll vote for you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.