适配器可以用在代码中动态构建的布局上吗?
我有一个 SQL 数据库,我正在向其中动态添加行和列。
我想将 SQL 数据库中的数据显示到 LinearLayouts 的 ListView 上,但由于行和列动态增长和收缩,我需要在代码中动态构建布局。
有没有办法使用 SimpleCursorAdapter 将数据映射到我的布局中?或者 SimpleCursorAdapter 只能用于静态定义的 XML 布局吗?
I have an SQL database that I am dynamically adding rows and columns to.
I want to display the data in the SQL database onto a ListView of LinearLayouts, but since the rows and columns are growing and shrinking dynamically, I am going to need to build the layout dynamically in my code.
Is there a way to use a SimpleCursorAdapter to map the data into my layout? Or can the SimpleCursorAdapter only be used on statically defined XML layouts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,好的。
除非对列数有限制,否则这可能会很困难。
仅当存在合理的最大列数时。在这种情况下,正如 @Maximus 建议的那样,您可以使用 View.GONE 隐藏未使用的列。否则,您最好使用
CursorAdapter
并相应地重写newView()
和bindView()
。Um, OK.
Unless you have limits on the number of columns, this may be difficult.
Only if there is a reasonable maximum number of columns. In that case, as @Maximus suggests, you can hide unused columns using
View.GONE
. Otherwise, you are better served usingCursorAdapter
and overridingnewView()
andbindView()
accordingly.