【发布时间】:2011-09-19 10:49:50
【问题描述】:
这是我的标题
public class MyAdapter extends ResourceCursorAdapter implements OnScrollListener {
在我的适配器中,我这样设置标签
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = super.newView(context, cursor, parent);
final MyCache cache = new MyCache();
view.setTag(cache);
}
比我有办法
public void metA(){
//here I want to read the tag
//how can I do that ?
}
我也实现了滚动监听器
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//how to read for example the third item in the list ?
//item.getTag() returns null
}
我尝试使用 getItem(0) 但我也收到空指针异常... 在 onScroll 方法中读取标签的正确方法是什么,视图实际包含什么? 我知道我做了一些非常愚蠢的事情,但我想不通。
【问题讨论】:
-
我可以看到你的适配器的全部来源吗?
-
它太大了,但它自己的适配器不是问题。我的问题是如何获取我在 newView 方法中使用 setTag() 设置的视图的标签 (getTag())。我的问题是如何阅读标签?
标签: android tags scroll nullpointerexception