Monthly Archives: June 2013

Avoid onItemSelected firing when spinner (or gallery) instantiated

Solutions (eg. see here) include counting the number of times the listener has fired usign a boolean to treat the first firing differently using a runnable to delay registering the listener. What seemed most appropriate (and simple) for me was … Continue reading

Posted in Android | Leave a comment

Get & set date / time and format

First tried this method: Calendar c = Calendar.getInstance(); int year, month, day, hour, minute; year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH) + 1; //months are 0-11 !! day = c.get(Calendar.DAY_OF_MONTH); hour = c.get(Calendar.HOUR_OF_DAY); minute = c.get(Calendar.MINUTE); String date1 = day + … Continue reading

Posted in Android | Leave a comment

Setting absolute position of view

Several useful comments in this question in stackoverflow. Key section fromAndy Zhang: You can use RelativeLayout. Let’s say you wanted a 30×40 ImageView at position (50,60) inside your layout. Somewhere in your activity:   // Some existing RelativeLayout from your … Continue reading

Posted in Android | Leave a comment

New buttons

A quick and simple way to create a new button style is to add into the layout android:background=”@drawable/custom_button” and have that custom_button.xml file in the drawable folder. An example follows. <selector xmlns:android=”http://schemas.android.com/apk/res/android” > <item android:state_pressed=”true” > <shape> <gradient android:startColor=”@color/sf_brown_light” android:endColor=”@color/sf_brown_lighter” android:angle=”270″ … Continue reading

Posted in Android | Leave a comment

Runnable updates textview in debug but not when run live

Had an interesting problem with a timer and runnables. The final outcome was to have the game timer outside of the main game runnable. I’ll explain what happened and put the code at the end. I had a simple game … Continue reading

Posted in Android | Leave a comment