仅在特定列表视图项目上显示项目
我试图让一个按钮显示在我的列表项上(在 XML 中声明为 android:visibility:"gone"),以便在我对其执行某些手势时显示为可见。但是,我如何才能正确通知 getView 方法以仅在列表视图项上显示按钮?
我尝试使用 getChildAt(position) ,它最终一次显示多个按钮。
我尝试传递位置,例如我检测到手势是从 pointToPosition 执行的,并将其传递到适配器中以供 getView 方法显示,但它也存在一次显示多个的相同问题。
有谁知道我该如何解决这个问题?
I am trying to get a button to show up on my list item (declared as android:visibility:"gone" in the XML) to show as visible when I perform some gestures on it. However, how can I actually notify the getView method correctly to display the button only on the listview item?
I tried using getChildAt(position) which ended up displaying several buttons at once.
I tried passing in the position for example I detected that the gesture was performed on from pointToPosition and passed it into the adapter for the getView method to display, but it had the same problem of displaying several at once.
do anyone know how can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能对 Adapter.getView() 的工作原理有误解,它的含义是在渲染 ListView 时创建或重用布局,它还需要快速,因此不鼓励在此方法中进行条件操作。尽管 ListView.getChildAt() 可能有效,但它并不能有效地使用 API。你的适配器将有一个 setViewBinder() 除非你使用 ArrayAdapter (如果是这样我建议使用 SimpleAdapter 因为有附加功能)。使用 ViewBinder 实现来切换按钮的可见性。
如果您希望继续使用 ArrayAdapter,请使用
ListView.getChildAt(int)
到findViewById(R.id.your_button).setVisibility()
。如果这是您已经尝试过的并且将所有按钮设置为可见,那么请发布相关代码。I think you may have a misunderstanding of how Adapter.getView() works its meant to create or reuse layouts when rendering the ListView it also needs to be fast so conditional manipulation in this method is discouraged. Although ListView.getChildAt() may work it does not effectively use the API. Your adapter will have a setViewBinder() unless you're using an ArrayAdapter (if so I suggest using SimpleAdapter because of the additional features). Use your ViewBinder implementation to switch the visibility of the button.
If you'd prefer to continue to use ArrayAdapter use
ListView.getChildAt(int)
tofindViewById(R.id.your_button).setVisibility()
. If this is what you already tried and its setting all the buttons visible then please post the related code.