I\'m setting a custom SimpleCursorAdapter to a ListView. For some reason FriendAdapter\'s getView() is called twice for every item in the DB. After some investigation (I have no
This is normal and can happen when you have a listview with height=wrap_content
(among others):
Look at the last post: http://groups.google.com/group/android-developers/browse_thread/thread/4c4aedde22fe4594
I used this. The getView
runs twice, but if you check if convertView
is null
, the code inside will be run once.
public View getView(int position, View convertView, ViewGroup parent) {
View superView = super.getView(position, convertView, parent);
if (convertView == null)
{
// Customize superView here
}
return superView;
}
For me it seems like the view is created twice in the same method. One in "if(convertView==null)" and the other "else". If I did nothing in once of the if statements then it is only created once. It seems like the method itself is only called once though.
In order to getView get call only once for each row, you need to call super.getView and then change the returned view. It's something like this
public View getView(int position, View convertView, ViewGroup parent) {
View superView = super.getView(position, convertView, parent);
if (mCursor.moveToPosition(position)) {
// Customize superView here
}
return superView;
}