适配器可以用在代码中动态构建的布局上吗?

发布于 2024-11-10 09:41:59 字数 207 浏览 4 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(1

汐鸠 2024-11-17 09:42:00

我有一个 SQL 数据库,我正在向其中动态添加行和列。

嗯,好的。

我想将SQL数据库中的数据显示到LinearLayouts的ListView上

除非对列数有限制,否则这可能会很困难。

有没有办法使用 SimpleCursorAdapter 将数据映射到我的布局中?

仅当存在合理的最大列数时。在这种情况下,正如 @Maximus 建议的那样,您可以使用 View.GONE 隐藏未使用的列。否则,您最好使用 CursorAdapter 并相应地重写 newView()bindView()

I have an SQL database that I am dynamically adding rows and columns to.

Um, OK.

I want to display the data in the SQL database onto a ListView of LinearLayouts

Unless you have limits on the number of columns, this may be difficult.

Is there a way to use a SimpleCursorAdapter to map the data into my layout?

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 using CursorAdapter and overriding newView() and bindView() accordingly.

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