如何从自定义适配器获取位置
在 myactivity 中,我为列表视图创建了一个自定义适配器。我有一个包含一个元素的数组。当我调用 setadapter 方法时,getView 方法运行了 10 次。
任何人都可以帮我解决这个问题...
In myactivity I have created one custom adapter for the listview.I have an array with one element. when I called setadapter method then the getView method running for 10 time.
Any one help me on this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须有一个内部类,多次调用 api 演示中的 ViewHolder。在那里你可以设置一个称为位置的整数。
如果convertView == null,则设置holder.position=position;
然后将holder(ViewHolder对象)设置为convertView的标签。每次您想查看 ConvertVIew 所在的位置时,让标签将其转换为 ViewHolder 对象并从那里访问该位置。
You have to have an inner class manytimes called ViewHolder from the api demos. There you can set an Integer called position.
Set holder.position=position if the convertView == null;
Then set the holder (ViewHolder object) as tag to the convertView. Eatch time you want to see what position is the ConvertVIew in, get the tag cast it to ViewHolder object and access the position from there.