1

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() {
        // TODO Auto-generated method stub
        return 0;
    }

    @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;
    }
}

and in my activity i do this:

[...]
rightDrawerLinearLayout = (LinearLayout) findViewById(R.id.right_drawer_ll);
rightDrawerListForFollow = (ListView) findViewById(R.id.right_drawer);
NavRightDrawerListAdapter adapter = new NavRightDrawerListAdapter(getApplicationContext(), userNameUsedForListView,returnBitMapFromURL);
rightDrawerListForFollow.setAdapter(adapter);
[...]

i notice that the getView is not being called, someone can explain me why?

thanks a lot.

Yokupoku Maioku
  • 493
  • 7
  • 21

2 Answers2

6

In your method

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

you are returning 0. so your method is not called. Instead return size of your list-view in getCount method.

Beena
  • 2,334
  • 24
  • 50
1

This has already been answered here:

Custom adapter getview is not called

Your getCount method is returning 0, so no need for the adapter to call getView().

Community
  • 1
  • 1
Michael Krause
  • 4,689
  • 1
  • 21
  • 25