Cogitas Blog:
Google Android,
Common Lisp,
programming
and web design.

How to create a basic Custom View in Google Android

Filed under: google android — Tags: , , — May 29, 2010

Google Android comes with many view widgets like Lists, Grids, Tabs and so on, but sometimes, you need your own Custom View. Using an example of a view that shows a list of images next to each other, here’s the steps to follow to start you off with your Custom View…

(Apologies for the poor layout of the code, it seems that I need to tweak the theme. This is the first time I am using the code tag and it’s not looking great :-( )

1. Create a class that extends View. In our example, let’s call it CustomView.

2. Create your constructor as below (this is the constructor to use if you load your View via xml).

public CustomView(Context context, AttributeSet attrs){
super(context, attrs);
}

(more…)