Skip to content Skip to sidebar Skip to footer

Android Custom Cursor Adapter

I have created an app for contact app. i have a problem in my cutom cursor adapter that has a two textview and Image view every time i scroll up and down the images is repeating on

Solution 1:

Here's a sample implementation of newView() and bindView().

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    Viewview= inflater.inflate(R.layout.list_item_whatever, null);
    ViewHolderholder=newViewHolder();
    holder.displayName = (TextView) view.findViewById(R.id.name);
    holder.groupId = (TextView) view.findViewById(R.id.groupId);
    holder.displayPhoto = (ImageView) view.findViewById(R.id.photo);
    view.setTag(holder);
    return view;
}

@OverridepublicvoidbindView(View view, Context context, Cursor cursor) {
    ViewHolderholder= (ViewHolder) view.getTag();
    if (holder.displayName != null) {
        holder.displayName.setText(getUserDisplayName(cursor.getString(userid)));
    }
    if (holder.groupId != null) {
        holder.groupId.setText(cursor.getString(group));
    }
    if (holder.displayPhoto != null) {
        holder.displayPhoto.setImageURI(imageUri);
    }
}

Also, for imageUri, you might want to get it from your cursor, too... Currently, you are using the same URI for all list items

Post a Comment for "Android Custom Cursor Adapter"