Typically, the two black wires are hot and load (the one coming from the circuit breaker being “hot” or “line”, and the one coming from the light/outlet being “load”) The white wire tucked inside is likely the neutral, and the bare or green wire is ground. (The fact that ground is present but not actually attached to the switch is odd.)
If you don’t have one already, I’d run out and get a non-contact voltage tester. Here’s an example: http://www.homedepot.com/p/Klein-Tools-Non-Contact-Voltage-Tester-NCVT-1SEN/100661787
(If you don’t have a tool like this, they are absolutely wonderful for testing if a wire has power or not, and can save you a shock when you just aren’t sure if something has power or not.)
Using that, turn the light off and test the two black wires. One should chirp (show voltage) and the other should be dead. The one showing voltage is the line/hot wire. The other is load.
In visual terms, the path of electricity in a typical circuit is from the circuit breaker, along the “hot/line” wire to the switch. From the switch to the load wire to the light fixture, and then BACK to the switch socket along the white/neutral wire, and then back to the circuit breaker.
OF course, knowing what kind of switch your trying to install would be useful. Some don’t use neutral, some do. Also knowing what you tried (specifically) would be useful for anyone to help.