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 an开发者_如何学编程d 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.
精彩评论