I am struggling with RecyclerView. I use the recycler view to display the details of my model class.
//My model class MyModel { String name; Double latitude; Double longitude; Boolean isOnline; ... }
Since some of the values ββmay be missing, I use RecyclerView with custom view types (one of which represents each value of my model).
//Inside my custom adapter public void setModel(T model) { //Reset values itemCount = 0; deviceOfflineViewPosition = -1; mapViewPosition = -1; //If device is offline, add device offline item if (device.isOnline() == null || !device.isOnline()) { deviceOfflineViewPosition = itemCount; itemCount++; } //Add additional items if necessary ... //Always add the map as the last item mapViewPosition = itemCount; itemCount++; notifyDataSetChanged(); } @Override public int getItemViewType(int position) { if (position == deviceOfflineViewPosition) { return ITEM_VIEW_TYPE_OFFLINE; } else if (position == mapViewPosition) { return ITEM_VIEW_TYPE_MAP; } else if (...) { //Check for other view types } }
With RecyclerView, I can easily determine at runtime which values ββare available and add the corresponding elements to the RecyclerView data source. I just used the code, but my model has a lot more values, and I have a lot more types of views.
The last element in RecyclerView is always a map and always present. Even if in my model there is no value, at least there will be one element, a map.
PROBLEM . How can I make the last element in RecyclerView fill the remaining space on the screen and also get the minimum value. The size should be what itβs ever cost: the remaining space or the minimum height. For example:
- The model has several values, which in total occupy 100dp of a 600dp screen β the map height should be 500dp
- The model has many values, which in total occupy 500dp of the screen 600dp β map heigh should be the minimum value of 200dp
- The model does not matter β the map fills the entire screen

android adapter google-maps android-recyclerview android-adapter
xxtesaxx
source share