The ternary operator[
^] is so-called because it consists of precisely three parts:
<test> ? <true part> : <false part>
You can't add extra parts at the end and expect the compiler to know what you want it to do!
You can combine multiple ternary operators:
<test 1> ? <test 1 true part> : (<test 2> ? <test 2 true part> : <false part>)
However, that isn't particularly easy to read.
A better solution is to us
the switch
statemet[
^]:
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Headlines";
case 1:
return "All News";
case 2:
return "Videos";
case 3:
return "Sports";
default:
return "# Unknown position #";
}
}