I’m working on an app and got to the point where I wanted to implement a drag and drop ListView that allows re-ordering, adding and deleting of list items using a database. I didn’t think that it would be all that difficult. However, with my limited experience with Android, it turned out to be a bit of a pain to get working. But, now that I have it working I figured I’d post some example code so that others can take advantage of what I learned and hopefully have an easier time getting this implemented.
So I’ve been playing around with Android and have a little app that I wanted the user to be able to shake the phone and have something happen. I did some digging and the following is a tutorial on how to setup a shake listener to capture a shake and then do whatever you want.
This is by no means something that I’ve created, I just used examples that I found on stackoverflow.com. Also, this uses G-force to calculate the shake threshold. Many thanks to Peterdk and Akos Cz for their input and answer for this solution. Peterdk recommended using the G-Force app by Blake La Pierre on Google Play Store if you want to get the actual G-force value on your phone and tweak it in the code below.… Read more...