List View..

FROM “The world of ListView, by Android – Romain Guy, Adam Powell” 
PDF download of slides is available on the site. Embeded Video is below.

ListView is mentioned. Exact same is for GridView.

1) ALWAYS do This: re-use your convertViews (they are Gauranteed to be of the correct type)
public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView=null) {
          convertView = mInflater.inflate(R.layout.item, parent, false);
     ((TextView) convertView.findbyId([position]);
     ((ImageView) convertView.findbyId(
                     (position & 1) == 1 ? mIcon1 : mIcon2);
     return convertView;
Adding that single if statement can increase speed and performance (memory, CPU..) by up to 150% (ie 2.5 times orig) on ListViews with a Very large number of elements.
No matter How many, or few, elements however, ALWAYS use the above technique.
There is no sense to Inflating more views than the phone’s screen can possibly dispay at any one time.. the overhead required is just tooo expensive!
..and it’s Very Bad Technique. Certainly, the requirement of the above it is Not (out of the the box) Obvious.. it just happens to be the way this element was created, and designed to be used.

2) Another technique that can increase performance by up to another 10% on ListViews with Very Large numbers of elements is to use the following technique:
Create a class to hold the elements in your listView:

Static class ViewHolder {
     TextView text;
     ImageView icon;

This is how the former code would then be re-written:

public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
      if (convertView=null) {
          convertView = mInflater.inflate(R.layout.item, parent, false);
     holder = new ViewHolder();
     holder.text = (TextView) convertView.findbyId(;
     holder.icon = (ImageView) convertView.findbyId(;

     }  else {
     holder = (ViewHolder) convertView.getTag();
     holder.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);

     return convertView;

GetTag can be anything… ?not real clear to me but maybe it’s the data??
Basically, it keeps the code from needing to search and find the [findbyId.. fields] each and every time.  The location of the XML fields are stored in the ViewHolder static class. So, now it already knows where you want to write the data, so it can just do so directly..
These can also hold very complex things such as constants, and database Queries
This is at about 12min into the video..


Much more content in this video.. I’m too newbie to digest just yet. Perhaps once I begin writing ListViews/GridViews would be a good time to watch again..
Always call notifyDataSet getDataChanged (or something like that)..
Headers and Footers (Page Title “Tweets”, “..Loading”)  (@26min)
textFilter, depending on Adapter: filters results depending on what the user has typed (like google search..), @35min
background or your list turns black..? see @39min
scrollbarchanges size..? see@40min
DONT set ListView android:layout_height=”wrap_content” @41min  Either use fill_parent, or in in linearLayout, can use height “0” and use weight; or set height to a fixed amount
DONT: ListView inside ScrollView !!! or vice versa.. use ListView’s header and footer @42min
Don’t cache views in the adapter EVER!! , etc @<26, maybe @20min, and again @43min  UsegetFirstVisible??onscreen, getChildItem..

So sometimes use LinearLayout, inside ScrollView instead. small data set notifyDataSetChanged..

displaying Day of Week in date picker Dialog box.. some prelim notes

Dialog, setTitle .. this may be how to display Thurseday, 5 Jan 2011, at top of datePicker Dialog..

also, onStart() -Called when the dialog is starting. //Dunno if this is relevant, or just set the title in onCreate method.

Guess that depends on if a new onCreate is called Every time the DatePicker (or other dialog) is called, even during the same session, or if it is called only the first time, and remembered, and instead onStart is called each subsequent time.

of course will need to update the date each time the user clicks a button, using the onTimeChanged() (listener-ish) method, and calling some sort of updateTitle function, that I create. the updateTitle function will read the (Date) info, format it, probably using SimpleDateFormat(), so the text appears how I wish, and then makes a call, probably to setTitle(), as noted in the first section.

Still Researching, however.

There is a Seperate classs called TimePickerDialog, seperate from TimePicker, So I don’t need to create a Dialog, and then put a TimePicker inside it.  Weird how they keep doing stuff like that.  Dunno if there are any advantages to this method, or if it winds up being slower code than putting a TimePicker inside one’s own dialog.. Guess I will just use this… damn soooo much vocabulary. Not just a few building blocks, a whole Dictionary, no, Encyclopedia Set to learn!  Sometimes it seems that it would be easier to have less.. and just build it, but then again, probably not!.. Argh.

Keep Looking Around.

Something neat about these, is that the constructors can be called with an optional extra parameter, specifying a Theme to use. 

Ahh, Themes, another thing to look into!! 🙂


onDateSetListener(), I think is used when the user chooses the date and presses OK/Set/whatever..

on…buton press, to update the text atop the dialog, while it is still open


Define a constant DEFAULT_THEME = 0

Then as write code, always use the format that passes a theme style. If 0 is passed, it uses the default (same as if that paramater wasn’t used at all).

Then as write themes for the dialogs, views,.. swap out DEFAULT_THEME with my theme name. Leaves no ambiguity -explicitly states in the code that no theme was used.. Or could simply pass only the 1 parameter, then update the code later by adding the second parameter, when a theme has been written. Guess that’s no extra work, because in either case, only 1 item is being changed.

SimpleDateFormat   “format”
public StringBuffer format (Date date, StringBuffer buffer, FieldPosition fieldPos)

So, to

progress on workoutTracker project

Got Scroll View working. (eeasy, once have a piece of code)

Got Time Picker working.

User sets new time, I display that in a text view, concatenating the returned values (plus “:” and formating elements) via StringBuilder.

However, it takes a picker with hr, min, am-pm

and displays as 23:59 format.

Need to find the variable name for the am/pm flag,

then use it to convert the time returned into a 12hr format..

-I added code to properly convert time to am-pm format :).

I see also a reference to SimpleDateFormat, which converts date-times (type Date)  to readableString and  formats. ie “E” (or”EEEE” = day of week, ie “Thurseday” (EEE=Thu),” a” returns AM or PM, h is hour in12hr, k is in 24hr.. y(ear)=20111, yyy=2011, but yy=11 :), Z(TimeZone) Z=”PST”, ZZZZ(4or more)= “Pacific Standard Time”, Month: MMM(3or more)=”July”, MM(2)=”07″  I am unclear when/how to use this as opposed to other method calls.

The code I used/wrote uses Calendar, but relies on methods that are depreciated c.get(calendar.DAY_OF_MONTH), c is type calendar, the variable passed is a calendar-defined constant, the method get is depreciated.

Same (?check?) with TimePicker.setCurrentHour().

Actually these are type Date.  getHours(), getMonth(), setMinutes() are depreciated. Instead use Calendar.set(Calendar.MINUTE, minute), etc

Time class defines integer constants for FRIDAY, JANUARY, WEEK_DAY, MONTH, etc..

Calendar is an abstract base class for converting between a Date object and a set of integer fields such as YEAR, MONTH, DAY, HOUR.

A Date object represents a specific instant in time with millisecond precision.

Calendar, especially subclass Gregorian Calendar has some strange properties, be careful when dealing with dates, such as Jan 33rd, Feb 29, etc. see documentation..

It also has Canstants defined for TUESDAY, MARCH, DAY_OF_MONTH (use in get and set methods),..

   getDisplayName(int field, int style, Locale locale) Returns a human-readable string for the value of field using the given style and locale.

   getTime() Gets the time of this Calendar as a Date object.

   toString() Returns the string representation of this Calendar

   constants AM_PM (get/set), AM(=0), PM (=1): the value of AM_PM

   HOUR (get/set) used for 12hour, HOUR_OF_DAY (get/set) used for 24hour

use Android Application Class for DatabaseManager – data helper

..a reference to  using Android Application Class for DatabaseManager

(not implemented in the example, but it’s a reference to follow up on later)
as code may get weighed down with perhaps-expensive creation and deletion of many DatabaseManager create calls.
Likely, I only need one global copy.

so that it gets declared once, then re-used, instead of recreated for each new view.

also, a small example of the various ways to use SQLite in code .

Ahaa.. How to Rename Projects and Files in Eclipse..

Use Navigator.. you get a Rename option upon right-click…

Package Explorer does Not give you this option

It is Impossilbe to rename the Project from Package Explorer..

and to Rename a  file from Package Explorer, you must:

 open file, save as.. (new name), then delete previous one

I wondered why Sometimes “Magically”,  I could “Rename”, and other times, the option Dissappeared !

Ha, Ha. So Happy Now

How To Bring Up Menu on Android emulator, using computer keyboard, and more …

Controlling the Emulator


Menu                      Page Up, or F2

Back                         Esc

Home                       Home

Portrait/Landscape mode     Ctrl-F11, Ctrrl-F12    switches to prev/next layout

Trackball Mode     F6             (now I know how to turn it off, and why it “randomly” starts ! 🙂

Full Screen mode                       Alt-Enter

Toggle code profiling                F9    (only with -trace startup option)

…several more available, including phone calls

Also the above webpage also has instructions for customizing the emulator.

There is some information regarding SDcard and storage, while using the emulator.

Useful later in development, when I don’t want to repopulate a database each time its restarted 🙂

An Introdution to SQLite
Richard Hipp, author of SQLite talks about its features and using it, as opposed to other variants of SQL.
This is a Google video, recorded in 2006. Mildly Interesting.

Since then, SQLite has implemented support for Foreign Keys.

However, I believe Android below 2.2, runs a version of SQLite that doesn’t support this feature, and even in Android 2.2 and above, the feature is turned off by default.

Evidentally, the way to use simulated foreign keys in Android, apparantly has to do with
here are a few pages that might be useful later:

Referential integrity with sqlite on Android the lazy way

For future reference: