将变量传递给 ViewBinder
我有一个 ViewBinder,它充当我的 ListView 和数据库游标适配器之间的中间人。根据显示数据的上下文,我需要 ViewBinder 来执行不同的操作。
以任务管理应用程序为例,它显示所有存在的任务组的任务。也许在这种情况下,应用程序希望在列表视图中显示任务组的名称,而如果它显示特定任务组之一的任务,则它不希望这样做。列表视图项可以有一个隐藏字段,ViewBinder
可用于将任务组的名称映射到该字段,并在必要时将其设置为可见(按照主应用程序的指示)。
我的问题是如何告诉 ViewBinder 它正在显示的上下文,以便它可以确定如何行为?
我意识到这可能可以通过实现许多不同的 ViewBinders 来完成,但这需要复制大量代码,并且更喜欢使用我刚刚传递的单个 ViewBinder 来完成某些参数到。
I have a ViewBinder
that is acting as the middleman between my ListView
and a cursor adapter to a database. Depending on the context this data is being displayed in, I need the ViewBinder
to do different things.
As an example, take a task management application, that is displaying tasks for all of the task groups that exist. Maybe in this case the app wants to display the name of the task group in the list view, when it wouldn't want to if it was showing tasks for one of the specific task groups. The list view item could have a hidden field, and the ViewBinder
can be used to map the task group's name to the field AND set it to visible when necessary (as instructed the main application).
My question is how would one tell the ViewBinder
the context in which it is displaying, so it can determine how to behave?
I realize this can likely be done by implementing many different ViewBinders
, but this would require much code to be duplicated, and would prefer doing it with a single ViewBinder
that I just pass certain parameters to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以通过实现您正在实现的 ViewBinder 的构造函数来完成。
根据示例,可以执行以下操作:
This can be done by implementing the constructor for the ViewBinder you are implementing.
Per the example, one can do something like this: