Spinner widget style

By default my spinner widget creates a popup with radio button. I want to have a small elegant dropdown instead.

I saw it in one of my previous exercises and know that’s a matter of style. But how..

Let’s gather info.

1. This has a good tutorial on how to style a spinner. However they are talking about making image buttons. I’m ok with text buttons. What’s a link ? (sorry i missed).

2. recommendation  to change style from Theme.Light to one of these (in styles.xml)



Let's try. This caused crash on startup about "unable to combine title with custom title". I had this problem when integrating custom title bar. Grr. Yes I remember the solution was to use Theme.Holo. No go. 
3. while waiting found this:


The available options are “dialog” and “dropdown”. This results in a dropdown style. But dropdown still has radio buttons, it’s a small elegant widget. Better but not good enough.

4. This post has a code sample for showing a dropdown in a target location. Seems as a good thing to  know about but I won’t try it now. http://stackoverflow.com/questions/13560432/android-change-spinner-dropdown-view

5. Trying adding style just to the spinner

style = “android:style/Widget.Holo.Light.Spinner” and removed  android:spinnerMode=”dropdown”

Well, it took my dropdown back to where I started. They were talking about parent style though. I don’t know how to set it.

6. Set  parent style

<style name="MyDropDownNav"   parent="android:style/Widget.Holo.Light.Spinner"> 
<item name="android:textColor">#ffffff</item> </style> 
7. Good find http://blog.stylingandroid.com/archives/297 blog about styling android  

Enouggh.. maybe all I want is to remove these radio buttons
1. http://stackoverflow.com/questions/1891809/android-spinner-how-to-remove-radio-buttons

2. adapterSpinner = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[]{"1", "2"});
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,
new String[]{"1", "2"}
); spinner.setAdapter(adapter); THISONE is a winner!!!!!!
plus android:spinnerMode="dropdown" in the resource file . Otherwise dialog shows in a middle of the screen without radio buttons. 

Now I have to see again people were talking about background color of the dropdown popup.
is expected to solve it

Bye now.

Device lifecycle : rotating the phone causes app problems

Today I will spend most of the time on stabilization. However one of issues is when device is rotated (90 degrees) which causes  loss of the image on a drilldown screen.

Relevant info:

1. Applications that match sensor data to on-screen display must always useandroid.view.Display.getRotation() to map sensor coordinates to screen coordinates

Deep explanation of imaging data with screen ration is http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html but it seems as overkill for me now.

2. Handling configuration changes http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange also seems as overkill

3. this seems a good explanation

<activity android:name=".MyActivity"

Now when one of these configurations change, MyActivity is not restarted. Instead, the Activity receives a call to onConfigurationChanged().

Implemented onConfigurationChanged() but it’s not called. Instead onCreate() is called each time device orientation is changed. Go figure.

4. Found this article with better explanation http://developer.android.com/guide/topics/resources/runtime-changes.html they say to override OnSaveInstanceState. This makes more sense.  This one is the winner.



4. Friend pointed to this cool software https://www.desktopanywhere.com/

ListView with expandable groups (categories)

English: Food2u running on an Android phone. E...

English: Food2u running on an Android phone. Español: Food2u funcionando en un teléfono Android. (Photo credit: Wikipedia)

Discovery one for today: setting table id as  autoincrement crashes code.  According to docs if field is declared as primary key it will autoincrement by itself. I wonder, why did they decide to crash it, they could have ignored the key word. Anyhow.

The next task is to create categories for input. Design considerations:

Input will be dropdown in the Edit screen with predefined enums. How would I show groups on a front screen? List with categories would be nice.  I’d   to reserve tabs for implementation of multi users.

Let’s explore lists with categories.

There is ExpandableListView

Replaced my old

android:layout_height=”289dp” >


android:layout_height = “match_parent”
</ExpandableListView >

I have to replace ListAdapter with ExpandableListAdapter in java code. reading http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html

This example seems to be what I need


Lunch stop. Stuck on creating this adapter. WTF is groupFrom and groupTo?

After 2 h successfully implemented expandable adapter. Took while to understand what these maps are but I got it!

After my expandable list started to work each time keyboard comes up at a startup. Found a fix by adding this line to manifest as property of this activity  android:windowSoftInputMode=”stateHidden”.


this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); or


Tomorrow is all about stabilization.

Other generally useful


Found info on testing . people say  You should have three (3) different devices:
1. One mobile phone (small screen) with Android 2.3 (e.g. HTC Wildfire)
2. One mobile phone (small screen) with Android 4.0+ (e.g. Samsung galaxy s3, s4)
3. One tablet (big screen > 7”) (e.g. Samasung galaxy Note 10.1)

ANother example of expandable list adapter but even less understandable

Save Bitmap for a future use in the application

Hello again.

Now we learned how to create an image, show thumbnail in the app and zoom it out.  Next step I have to save this image (bitmap) somewhere so that app can use it. Normally in enterprise application this would be saved in Oracle database under another table with userId and itemId. I am tempted to create a new table in SQLite and link it with other tables. Before going for it let’s explore if better alternative exists for android. I am hoping for ability to save image  using content provider and stick URI into my table for allergen descriptors.

What people say..

Uri.fromFile(new File(Environment.getExternalStorageDirectory(), “your_file_name”)))

Save ringtone to sdcard:http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/ This is asking for a specific folder name on sd card. How do I know if card exists.. and what folders already are there.  They create a folder if it doesn’t exists. Maybe.

This seems more hopeful http://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database  But people say that saving images in SQLite is not a good practice.

This has code for downloading stream and saving into file. Bit I don’t have stream. How would I make a stream out of bitmap?

Going with SQLite database solution though it’s not a good practice I only have few images.

Next issue: database model planning. I already have couple tables. And I had 4 tables in a previous app. Will try to organize it more efficient but prevent complex queries.

Spent 4-6 hours refactoring so I track items by id and can translate individual items not lists. This was my smart caching task. Almost done need more verifications and bugfixes.

I have now images table that are id’ed by group id. Can be saved/restored as byte[]. Still debugging, zoom is not working after a round trip to a database.

Have to finish this before noon.  Next will be drop down for categories, I never did dropdown menus.



Take photo with my device camera

Yesterday I learned how to look up image in a gallery and copy it into my app. Today I have to learn to take a photo instead of using an existing one.

1. Gist of it is explained in android doc

Use the Camera.takePicture() method to take a picture once the preview is started. You can createCamera.PictureCallback and Camera.ShutterCallback objects and pass them intoCamera.takePicture().

2. Code from http://developer.android.com/training/camera/photobasics.html starts camera and allows to take a picture. This is great. How do I get the image into my app?

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);

3. onActionResult added code

Bundle extras = imageReturnedIntent.getExtras();
Bitmap yourSelectedImage = (Bitmap) extras.get(“data”);

This is working! Yey. Image is saved in a gallery. I don’t need it to be there but it’s ok.

Thumbnail Images and zoom window

My customer asked to be able to take photos and place 2-3 images into a drill down screen.

How do I do that? no idea.

Started with adding 2 ImageView as containers.

Reading how to use camera in the app. http://developer.android.com/training/camera/photobasics.html

 <uses-feature android:name="android.hardware.camera" />

This post has lot of useful info and code


I was able to add ImageView and respond to OnClick. It goes now to my gallery and I can pick an image. Then icon is created and displayed ib my Image View. However I can’t enlarge it.

Reading how to zoom an image. And I need to respond to multitouch ( for zoom)

I didn;t find info about capturing multi-touch. Instead I remembered Chase app that makes people take photos.

Found code that allows selecting from Gallery instead of taking photos. Ok for now.

Found code http://developer.android.com/training/camera/cameradirect.html for zoom. Went with this one and it works. 22:52 pm.

Result: I have two areas inside of Relative Layout. One for MedsBottle and one for Rx.  Two Linear Layouts each with textView, button and ImageView. Also one ImageView outside of LinearLayout will be used as zoom window.

Text is for explanations. Button triggers selecting from gallery. Click on image brings up animation with zoom.

Problems (to do tomorrow) (1)selecting second time barfs out.(2)Turning device loses images. (3)Images are not saved in a database. Enable to save and view later (4) try to take picture rather than select from gallery.





additional info that could become useful

Icon templates and guidelines:


Providing alternate resources for other screen sizes:


Language translation APIs

Looking for free alternatives to google translation APIs.

Google translation service is great but it’s a paid service. Today I am looking for free alternatives.

Yandex.ru. Easy to integrate, functional. However this service supports limited set of languages and some languages don’t work and for some languages I encountered exceptions on translating some words, not very complex words.

Extended info on google translate

echo GoogleTranslate::staticTranslate("Hello again", "en", "ka");

Found a post on stackoverflow recommending to look into these, no info if they are free or functional.

Alternatives to Google Translate API:

Microsoft Translator APIs this guy is talking about it with a bit of incomplete example: http://web.archive.org/web/20110720142541/http://basharkokash.com/post/2010/04/19/Bin g-Translator-for-developers.aspx

Speaklite Translate API – http://www.speaklike.com/plans/ this is 6 cents per word. REST interface
WebServiceX Translate API  – limited set of languages. SOAP interface.


MyGengo  – http://gengo.com/pricing-languages/ This is super expensive. priced per word, no free nothing.


http://www.translatorbox.com/google-text-translator-alternative-for-wordpress/ – nonsense. exposes a box for use in web apps.


MyMemory translation: http://mymemory.translated.net/api/get?q=Hello World!&langpair=en|it

You can find the API docs here: http://mymemory.translated.net/doc/spec.php Free use is limited to 100 requests/day. 


Summary: no good. will have to pay google translation or pre-build my cache.