Ayden
01/12/2018, 10:21 AMview as Button
means?vincent.desmet
01/12/2018, 10:23 AM(Button) view
does in Javamenegatti
01/12/2018, 10:24 AMview
cannot be cast to Button
it will throw an exceptionAyden
01/12/2018, 10:26 AMval btnSelected = Button
.menegatti
01/12/2018, 10:27 AMmenegatti
01/12/2018, 10:27 AMclickListener
and you’re using the view
passed as a parametermenegatti
01/12/2018, 10:28 AMBenoît
01/12/2018, 10:28 AMButton b = (Button) yourView;
Ayden
01/12/2018, 10:28 AMmenegatti
01/12/2018, 10:30 AMas X
is the way to cast an object to another typeAyden
01/12/2018, 2:11 PMmenegatti
01/12/2018, 2:14 PMmenegatti
01/12/2018, 2:14 PMmenegatti
01/12/2018, 2:15 PMas
means “from this point treat this object type as the type of the cast”menegatti
01/12/2018, 2:17 PMval btnSelected = view as Button
val
means that the field btnSelected
is read-only
=
causes btnSelected
to be set to view
view as Button
forces view
to be treated as a Button
instead of View
Ayden
01/12/2018, 2:42 PMAyden
01/12/2018, 2:42 PM