Monthly Archives: December 2013

Set spinner style

This is simple to do in xml. This example makes the spinner look like an edit text. In styles xml file add <style parent=”@android:style/Widget.Spinner” name=”SpinnerAsEditText”><item name=”android:background”>@android:drawable/edit_text</item> </style> In layout file add spinner. <Spinner android:id=”@+id/spinner1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” style=”@style/SpinnerAsEditText” />  

Posted in Android | Leave a comment

Create spinner from array

Create a sinner and an adapter, link the two then add to the layout. Use array from strings xml file or created programmatically. LinearLayout myLayout = (LinearLayout) findViewById(R.id.layout1); ArrayList spinnerArray = new ArrayList(); spinnerArray.add(“a”); spinnerArray.add(“b”); spinnerArray.add(“c”); Spinner spinner = new … Continue reading

Posted in Android | Leave a comment

Get API level programmatically

The SDK level (integer) running is available in android.os.Build.VERSION.SDK_INT. int currentapiVersion = android.os.Build.VERSION.SDK_INT; You can then use the int value or the enum corresponding to this int in the android.os.Build.VERSION_CODES class. if (currentapiVersion >= 18) or if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO)  

Posted in Android | Leave a comment

Assign R.id to dynamically created editText

With thanks to stackoverflow, 2 methods, 1 simple and one less simple. 1) You can assign an id after creating the edit text and before adding it to the layout. e.setId(int) This doesn’t put it in the R.java file (so … Continue reading

Posted in Android | Leave a comment