From PHP to Android, the simple stuff – What about arrays

Featured Image

Recently I have been engaged in Android development. Most of my work is focused on Magento-Android related app. This PHP to Android step actually means PHP to Java (with some sugar on top of it).

Although there are significant difference between Java and PHP, personally I find Java pretty easy. Most likely due to my past experience with C# language. Anyhow, lets get back to the topic of this post “From PHP to Android, the simple stuff – What about arrays”.

If you are experienced everyday developer then process of switching from one programming language to another one is simply a matter of things like: what about flow statements, what about collections, what about types, etc. So for a PHP developer trying to pick up Java, arrays are pretty interesting concept.

In PHP arrays are this holly grail that is trully powerful and yet so simple. In PHP you can place (almost) everything you wish in array, whether is a object, string, integer, etc. Combining that with foreach loop, PHP developers got themselves a pretty powerful but simple collection looping mechanism.

Logically when switching to another programming language you wish to quickly pickup on these everyday operations and learn how to manage them appropriately.

My first need for “arrays” in Android came up when I was trying to build an appropriate list like the one shown on the photo below.

And below is the appropriate Java code for building this ListView.

ArrayList<hashmap <String, String>> list = new ArrayList</hashmap><hashmap <String, String>>();
 * PHP version
 * $item = array('name'=>'Branko', 'lastname'=>'Ajzele', 'email'=>'');
 * $item2 = array('name'=>'Tomislav', 'lastname'=>'Bilic', 'email'=>'');
 * list = array($item, $item2);
HashMap<string , String> item = new HashMap</string><string , String>();
HashMap</string><string , String> item2 = new HashMap</string><string , String>();
HashMap</string><string , String> item3 = new HashMap</string><string , String>();
HashMap</string><string , String> item4 = new HashMap</string><string , String>();
item.put("name", "Branko");
item.put("lastname", "Ajzele");
item.put("email", "");
item2.put("name", "Tomislav");
item2.put("lastname", "Bilic");
item2.put("email", "");
item3.put("name", "Vedran");
item3.put("lastname", "Subotic");
item3.put("email", "");        
item4.put("name", "Zeljko");
item4.put("lastname", "Prsa");
item4.put("email", "");        
String[] columns = new String[] { "name", "lastname", "email" };
int[] renderTo = new int[] {,, };
ListAdapter listAdapter = new SimpleAdapter(this, list, R.layout.sales_order_list_row, columns, renderTo);

And for those of you interested, here is the entire source code for this sample app. Might come in handy for those of you trying to make a ListView with specific list row look and feel, row with more then just one text label.


  1. how much time it will take to clearly learn the android??? as because i am a pure php guys,plz help me out this, coz i like this platform a lot..

  2. Hello, I’m new to this and I would like to build a small script that could build SQLite database, insert some values and select them to be displayed in dialog alert or toast… Is that possible? I’ve been trying out some cases but I just can’t get a hold of that. 🙂

  3. Hi. Really it helped me a lot! Much better than other sucky tuts on the internet (at least those i’v seen…)

  4. I have read about 10 ListView with more then just 1 TextView per item Tutorials and none of them helped.

    This one however, was awesome!
    Got me going in 5 minutes.

    Thanks buddy.

  5. @Rabe’e AbdelWahab

    I would suggest learning Java as a part of learning Android. Java is not that hard if you are on top with OOP concepts in PHP.

  6. I am also trying to start with Android development as a very interesting mobile software and OS.

    And i am purely a PHP developer , never tried another language , trying to concentrate on one, and now is the time to try something new.

    My question is, do you advice i go for Java first before Android, or should i learn through Android itself ?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.