具有自定义对象的可扩展 ListView

发布于 2024-12-05 17:46:49 字数 381 浏览 4 评论 0原文

我对 android 还很陌生,正在慢慢适应 android 的工作方式。

我正在创建一个 Android 应用程序,它使用 .net Web 服务从 SQL 数据库中提取数据。我有两种方法返回带有自定义对象列表的 json 响应。

我正在将它们解析为 Android 客户端上的匹配对象数组。我希望实现一个多层网格来显示这两个数组的信息。第一个数组中的项目将具有第二个数组中包含的子项目。(一对多关系)

我猜我需要创建两个自定义数组适配器? (这将允许我为每一层都有自定义布局)。

我环顾四周,努力找到使用可扩展列表视图的综合示例。这需要什么数据源? (我会想象某种哈希表?)

我上面的方法听起来合理吗?

任何建议将不胜感激。

谢谢,

I'm fairly new to android and am slowly adjusting to how android works.

I am in the process of creating an android application which uses a .net web service to pull back data from a sql database. I have two methods which return a json response with a list of custom objects.

I am parsing these into arrays of matching objects on the android client. I am looking to implement a multiple tier grid displaying information from these two arrays. The items in the first array will have child items contained within the second array.(one to many relationship)

I am guessing I will need to create two custom array adapters? (which will allow me to have custom layouts for each tier).

I have had a look around and struggled to find a comprehensive example of using the expandable list view. What data source will this expect? (some kind of hash table I would imagine?)

Does my approach above sound reasonable?

Any advice would be appreciated.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

尬尬 2024-12-12 17:46:49

ExpandableListView 需要一个实现接口 ExpandableListAdapter 接口的类 作为数据源。 Android SDK 中包含多种实现。 SimpleExpandableListAdapter 可能会让您起床并运行速度最快,它使用列表和地图来获取数据。它不会让您能够为列表中的每个组使用不同的布局,但它会让您为组和子项使用不同的布局。

如果 SimpleExpandableListAdapter 还不够,那么您将需要编写自己的适配器。我建议扩展 BaseExpandableAdapter (这Adapter 实现了 ExpandableListAdapter 并为您处理一些内务工作,它将其余的实现留给您)。 API 演示中有一个简单的示例演示如何执行此操作 ExpandableList1.java 示例

您的实现可能比示例更复杂,但它应该让您了解如何实现。

ExpandableListView expects a class which implements the interface ExpandableListAdapter as the data source. There are several implementations included in the Android SDK. The SimpleExpandableListAdapter would probably get you up and running the fastest, it uses Lists and Maps for it's data. It won't give you the ability to use different layouts for each group within the list but it will let you have a different layout for groups and children.

If SimpleExpandableListAdapter isn't enough then you are going to want to write your own adapter. I'd suggest extending BaseExpandableAdapter (this Adapter implements ExpandableListAdapter and takes care of some of the housekeeping aspects for you, it leaves the rest of the implementation to you). There is a simple example that shows how to do this in the API Demos ExpandableList1.java example.

Your implementation will likely be more complex than the example, but it should give you some idea how to do it.

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