2

i have this class which extends BaseAdapter that i use to insert an icon and a textView for each row of a listView that is inside a drawer

public class NavRightDrawerListAdapter extends BaseAdapter {

private Context context;
LinkedList<String> userNameUsedForListView;
Map<String, Bitmap> urlUserImage;

public NavRightDrawerListAdapter(Context context, LinkedList<String> userNameUsedForListView, Map<String, Bitmap> returnBitMapFromURL) {
    this.context = context;
    this.userNameUsedForListView = userNameUsedForListView;
    this.urlUserImage = returnBitMapFromURL;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    int count = 0;
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.drawer_list_of_action, null);
    }

    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

    imgIcon.setImageBitmap(urlUserImage.get(userNameUsedForListView.get(count)));
    txtTitle.setText(userNameUsedForListView.get(count));
    count++;
    return convertView;
}

@Override
public int getCount() {
    return userNameUsedForListView.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

my list size is 1, and getView is called 1 time,normally, but getCount is called six times? why? is a normal behaviour?

i didn't implement the method,getItem() and getItemId(),because i don't need them, i have to implement them anyway?

thanks a lot.

Yokupoku Maioku
  • 493
  • 7
  • 21
  • 1
    Adapter methods may be called an arbitrary number of times while the AdapterView is readying and laying out its child Views. So, yes, it's normal. – Mike M. Sep 21 '14 at 08:27

1 Answers1

1

Adapter methods may be called an arbitrary number of times while the AdapterView is readying and laying out its child Views. So, yes, it's normal.

I'm unable to find a source that explicitly states that this is the case for getCount(), but this answer by Romain Guy notes how there is no guarantee how many times getView() will be called. One can see how that method would interplay with getCount(), which would, therefore, also need to be called an uncertain number of times.

Community
  • 1
  • 1
Mike M.
  • 38,532
  • 8
  • 99
  • 95