Tuesday, October 19, 2010

Using a GridView to layout your app screen.

 

For many of us coming from other platforms to android development the idea of using an xml definition sheet to plan your display may feel very foreign, or maybe it just me,  whether you are coming from web development or using a development tool such as Visual Studio the ability to place your buttons or controls in a nice formatted layout can be a tricky one. 

For my first android application I have decided to use androids GridView as a way to place mock buttons in a nice formatted fashion on to my screen rather then using androids button control I will use the GridView control to layout a pattern of images which will act like buttons for my application.

First let me recommend reading Android Developers GridView Tutorial 'Hello Views'.  This is what I used for the base layout of my application.  Using the public ImageAdapter provided in the tutorial I add a listener to the click event to launch 4 separate activities tied to the 4 images I used as mock buttons.

GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter(this)); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { switch (position) { case 0: Intent myIntent = new Intent(v.getContext(), MyClass0.class);startActivityAct0(myIntent, 0);break; case 1: Intent myIntent1 = new Intent(v.getContext(), MyClass1.class);startActivityAct1(myIntent1, 0);break; case 2: Intent myIntent2 = new Intent(v.getContext(), MyClass2.class);startActivityAct2(myIntent2, 0);break; case 3: Intent myIntent3 = new Intent(v.getContext(), MyClass3.class);startActivityAct3(myIntent3, 0);break; } } });

Now when any of the 4 images are clicked by the user it will launch into a new activity.

Hope this helps.

Friday, October 15, 2010

Android App Development

Welcome to Pev's Android Development blog.  This blog will be used to post information on Android Development as I develop my first android app.  I will post updates and notes on what I find while developing my application and hope to hear from other application developers as well.  Would love to share tips, tricks, and best practices along the way.


Welcome to Pev's Android Development !!!