getView() (for a Custom ListView ) doesn't get called on notifyDatasetChanged()
Posted
by
hungson175
on Stack Overflow
See other posts from Stack Overflow
or by hungson175
Published on 2010-12-30T14:13:01Z
Indexed on
2010/12/31
1:54 UTC
Read the original article
Hit count: 493
android
Hi everyone,
I have the following problem, and searched for a while but haven't got any solution from the net:
I have a custom list view, each item has the following layout (I just post the essential):
<LinearLayout>
<ImageView android:id="@+id/friendlist_iv_avatar" />
<TextView andorid:id="@+id/friendlist_tv_nick_name" />
<ImageView android:id="@+id/friendlist_iv_status_icon" />
</LinearLayout>
And I have a class FriendRowItem, which is inflated from the above layout:
public class FriendRowItem extends LinearLayout{
private ImageView ivAvatar;
private ImageView ivStatusIcon;
private TextView tvNickName;
public FriendRowItem(Context context) {
super(context);
RelativeLayout friendRow = (RelativeLayout) Helpers.inflate(context, R.layout.friendlist_row);
this.addView(friendRow);
ivAvatar = (ImageView)findViewById(R.id.friendlist_iv_avatar);
ivStatusIcon = (ImageView)findViewById(R.id.friendlist_iv_status_icon);
tvNickName = (TextView)findViewById(R.id.friendlist_tv_nick_name);
}
public void setPropeties(Friend friend) {
//Avatar
ivAvatar.setImageResource(friend.getAvatar().getDrawableResourceId());
//Status
Status.Type status = friend.getStatusType();
if ( status == Type.ONLINE) {
ivStatusIcon.setImageResource(R.drawable.online_icon);
} else {
ivStatusIcon.setImageResource(R.drawable.offline_icon);
}
//Nickname
String name = friend.getChatID();
if ( friend.hasName()) {
name = friend.getName();
}
tvNickName.setText(name);
}
}
In the main activity, I have a custom listview: lvMainListView, with an custom adapter (whose class extends ArrayAdapter - and off course: override the method getView ), the data set of the adapter is: ArrayList<Friend> friends
:
private class FriendRowAdapter extends ArrayAdapter<Friend> {
public FriendRowAdapter(Context applicationContext, int friendlistRow,
ArrayList<Friend> friends) {
super(applicationContext, friendlistRow, friends);
}
@Override
public View getView(int position,View convertView,ViewGroup parent) {
Friend friend = getItem(position);
FriendRowItem row = (FriendRowItem) convertView;
if ( row == null ) {
row = new FriendRowItem(ShowFriendsList.this.getApplicationContext());
}
row.setPropeties( friend );
return row;
}
}
- the problem is when I change the status of a friend from OFFLINE to ONLINE, then call notifyDataSetChanged(), nothing happens : the status icon of that friend doesn't change.
I tried debugging, and saw the code: notifyDataSetChanged() get called, but the custom getView() is not fired !
Can you please tell me, that is normal in Android, or did I do something wrong ? (I am using Android 1.5).
Thank you in advance,
Son
© Stack Overflow or respective owner