作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个扩展 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/
我是一名优秀的程序员,十分优秀!