在baseAdapter类上没有调用getView

时间:2014-09-20 16:27:49

标签: android listview navigation-drawer baseadapter

我有这个类扩展BaseAdapter,用于为抽屉内的icon的每一行插入textViewlistView

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

在我的活动中我这样做:

[...]
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);
[...]

我注意到getView没有被调用,有人可以解释我为什么?

非常感谢。

2 个答案:

答案 0 :(得分:6)

在你的方法中

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

你返回0.所以你的方法没有被调用。而是在getCount方法中返回list-view的大小。

答案 1 :(得分:1)

这已经在这里得到了解答:

Custom adapter getview is not called

你的getCount方法返回0,所以不需要适配器调用getView()。