如何从自定义适配器获取位置

发布于 2024-12-16 21:01:43 字数 119 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尝蛊 2024-12-23 21:01:43

您必须有一个内部类,多次调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文