Okay, so here's the thing. Your code, as is, does the following things with every call to getView():
1. Instantiates a new dialog, using a row (?) layout from your resources.
2. finds a sub-view inside that dialog, and sets its layout parameters.
3. Finally, runs through your data to populate the sub-view.
1 and 2 are unnecessary (and expensive), especially since (as the video mentions) the framework may call getView() several times for measurement purposes only. Removing those two steps entirely will wildly simplify the process of 3, and make your life a lot easier.
Here's the entire code I used for a simple list adapter:
Code:
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
View tag = row.findViewById(R.id.colorstrip);
c.moveToPosition(position);
//On every other row, we're going to add a slight grey tint.
//In the light theme, this darkens it, and in the black theme it lightens it.
//If we used custom colors, this should still work over an arbitrary list background.
//This stripe effect could be made optional pretty easily.
if (position % 2 == 1) {
row.setBackgroundColor(0x20808080);
} else {
row.setBackgroundColor(0x00FFFFFF);
}
tag.setBackgroundColor(c.getInt(DB_COLOR));
return row;
}
You will note that mine is a lot simpler than yours. That's because all mine does is worry about returning a view with data filled in. The other stuff is up to the framework that calls the Adapter.
If I were you, I'd instantiate the dialog separately, setContentView() to a ListView-based layout, and then set that ListView's adapter to your adapter class. That's a lot simpler, it avoids instantiating/parsing a bunch of unused dialogs, and it will take advantage of the heavy optimizations in the framework for populating views from an adapter.