Can I get a virus from connecting to a WiFi network?
Depends on your OS and a lot of variables but in general yes.
Because the attacker may perform a man in the middle attack on a poorly designed update mechanism (not windows update) and or (again depending on your setup) abuse windows' local features like printer sharing as an attack vector.
As with everything there is no 100% solution but a very good start is using a VPN in order to fully encrypt all in/outgoing traffic and verify its integrity.
If your OS has no security problem and you have only applications with no security flaws in any of them, if you have no poorly configured active server program, if your system is strongly secured with a state of the art paranoidly configured firewall and if you have no dangerous activity like browsing on uncontrolled sites, an attacker should only be able to trace your unencrypted traffic.
In you have some sensitive data on your disk, you should be aware that everything that you receive from the network and that is not digitally signed with a trusted certificate can be forged by a Man In The Middle attack. That could include any software update, or even any data that could exploit a security flaw in a normally harmless application like an image displayer or as on-line game.
TL/DR: if your smartphone contains no more than you last holidays photos, no extra application and of course is not rooted, the risk is limited. If you have an ordinary PC with no special security configuration and are connected as an administrator, you'd better switch the WiFi off...