简体   繁体   English

如何在异步更新文本和图像的情况下显示各种单元格布局?

[英]How to display varying cell layouts with asynchronously updating text and images?

I am working on a remote controlling app for a home automation system. 我正在为家庭自动化系统开发一个远程控制应用程序。 The mobile and the home automation device communicate via WebSockets. 移动设备和家庭自动化设备通过WebSockets通信。

To display the functions of the automation device, I am currently using ListViews and Adapters with a varying cell layout. 为了显示自动化设备的功能,我目前使用具有不同单元格布局的ListViews和Adapters。 One adapter is displaying all of the device's functions. 一个适配器正在显示设备的所有功能。

The biggest problem I encountered: Adapters keep calling getView() very often , which triggers my functions to register themselves with my state handle and action dispatcher over and over again. 我遇到的最大问题是: 适配器经常调用getView() ,这会触发我的函数一次又一次地向状态句柄和动作分配器注册自己。

Please note: 请注意:

  • There are about 20 different types of functions, all of them requiring a different cell layout. 大约有20种不同类型的功能,所有这些功能都需要不同的单元布局。 There are sliders, buttons, state text, ... 有滑块,按钮,状态文本,...
  • The functions have asynchronously updating states. 这些功能具有异步更新状态。

I need to find a way to display those functions in a ListView or a ListView-like layout. 我需要找到一种在ListView或类似ListView的布局中显示这些功能的方法。

Can you please help me? 你能帮我么?

Make sure to implement BaseAdapter.getViewTypeCount() which should return the count for the number of different view types your listView is expected to have for its enteries. 确保实现BaseAdapter.getViewTypeCount(),该方法应返回listView预期为其输入对象所具有的不同视图类型的数量的计数。

And also implement ListAdapter.getItemViewType(int position) to return an int that identifies a specific view and which view type it will be. 并且还实现ListAdapter.getItemViewType(int position)以返回一个int,该int标识特定视图以及该视图将是哪种视图类型。

Following the above two recommendations will ensure that your ListView will be efficient and it will guarantee that your getView(...) method is called with the appropriate view type, if there is one already infalted. 遵循以上两个建议将确保ListView高效,并且如果已经存在,则将确保使用适当的视图类型调用getView(...)方法。

That said, if you have a few fixed number of view in your list and they are all different, then consider using LinearLayout in a ScrollView. 就是说,如果您的列表中有几个固定数量的视图,并且它们都不同,那么可以考虑在ScrollView中使用LinearLayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM