简体   繁体   中英

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.

To display the functions of the automation device, I am currently using ListViews and Adapters with a varying cell layout. 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.

Please note:

  • There are about 20 different types of functions, all of them requiring a different cell layout. 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.

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.

And also implement ListAdapter.getItemViewType(int position) to return an int that identifies a specific view and which view type it will be.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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