android

android tips and tutorials

MyShake: A free app that has the ability to recognize earthquake shaking

Per their website: “MyShake is a free app for Android phones that has the ability to recognize earthquake shaking using the sensors in every smartphone. The app runs ‘silently’ in the background on your phone using very little power – just like the step-tracking fitness apps. When the shaking fits the vibrational profile of an earthquake, the app sends the anonymous information to our central system that confirms the location and magnitude of the quake.”

“Our goal is to build a worldwide seismic network and use the data to reduce the effects of earthquakes on us as individuals, and our society as a whole. MyShake also provides users with information about recent earthquakes around the world and significant global historical earthquakes.”

An Android ListView with the Back/Up/Home button enabled

Without much discussion, here’s an Android ListView/ListFragment with its Back/Up/Home button enabled:

An Android ListFragment/ListView with Back/Up button enabled

(That button used to be a Home button, but now it’s used for the Back/Up action.)

And here’s the source code for that ListView/ListFragment:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

A simple way to populate an Android ListView with a SQLite database Cursor

Here’s an example of how to populate an Android ListView, where I get the data for the ListView from a database Cursor:

DatabaseHelper.TeamsCursor tc = DatabaseManager.get(getActivity()).getAllTeams();
ArrayList<String> listOfTeamNames = new ArrayList<>();
for(tc.moveToFirst(); !tc.isAfterLast(); tc.moveToNext()) {
    listOfTeamNames.add(tc.getTeam().teamName);
}

// list the team names with an adapter that talks to our listview
TeamNamesAdapter adapter = new TeamNamesAdapter(listOfTeamNames);
setListAdapter(adapter);

There are more formal ways to create an adapter class to work with a Cursor, but for my needs I just needed to get a list of names from a SQLite database table and show them in a simple ListView — part of a ListFragment — and this was the simplest code to write.

FWIW, the example also shows one way to iterate over the elements in a Cursor using a Java for loop.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Source Code to The Busy Coder's Guide To Advanced Android Development alvin January 24, 2017 - 4:39pm

This link has the source code for the online book, The Busy Coder's Guide To Advanced Android Development.

Source code to get an Android TableRow to align elements right

As a quick note, if you need to get an Android TableRow to align right, I can confirm that this layout code works:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

How to set Android Spinner data (array) from Java code

As a quick note, this source code shows how to set the data (array) on an Android Spinner from Java code:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Android SQLiteOpenHelper example source code

Here’s an Android SQLite class I use in an Android app I wrote in 2014-2015. I’m sharing it here so I can easily find an Android SQLiteOpenHelper example:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.