gpt4 book ai didi

android - getView 未在 baseAdapter 类上调用

转载 作者:行者123 更新时间:2023-11-29 14:37:44 25 4
gpt4 key购买 nike

我有一个扩展 BaseAdapter 的类,我用它来为 listView 的每一行插入一个 icon 和一个 textView 在抽屉里

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

在我的 Activity 中我这样做:

[...]
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,有人可以解释为什么吗?

非常感谢。

最佳答案

在你的方法中

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

您将返回 0。因此您的方法未被调用。而是在 getCount 方法中返回 ListView 的大小。

关于android - getView 未在 baseAdapter 类上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25950901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com