title: Android databinding in an expandable listview
body: <p>I have a very specific Question. I am using the android databinding library:
  <a href="https://developer.android.com/topic/libraries/data-binding/index.html" rel="noreferrer">https://developer.android.com/topic/libraries/data-binding/index.html</a></p>
  
  <p>I have a datamodel like this:</p>
  
  <pre><code>Class Participant
  Public String Name;
  //and so on
  Public ObservableArrayList&lt;Drink&gt; DrinkList;
  End Class
  Class Drink extends BaseObservable
  @Bindable
  Public String Name;
  @Bindable
  Public Float Price;
  End Class
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>Class ParticipantList 
  public ObservableArrayList&lt;Participant&gt; list = new ObservableArrayList&lt;&gt;();
  //some Methods to add items and concstructor
  </code></pre>
  
  <p>I use also Getter and Setter for all @Bindable fields.</p>
  
  <p>Now I have an activity with an expandablelistview where I bind an adapter to the expandablelistview via XML and an custom @BindingAdapter like this:</p>
  
  <pre><code>//in XML for the layout
  &lt;layout xmlns:bind="http://schemas.android.com/apk/res-auto"
     &lt;data&gt;
         &lt;variable name="Participants" type="com.example.ParticipantList"/&gt;
     &lt;/data&gt;
  &lt;ExpandableListview&gt;
  &lt;bind:participants=Particpants.list&gt;
  </code></pre>
  
  <p>In a binding helper Class this static method</p>
  
  <pre><code>    @BindingAdapter("participants")
  public static void bindList(ExpandableListView view, ObservableArrayList&lt;Participant&gt; list) {
      ParticipantListAdapter adapter = new ParticipantListAdapter(list);
      view.setAdapter(adapter);
  }
  </code></pre>
  
  <p>and finally my adapter:</p>
  
  <pre><code>Class ParticpantListAdapter Extends ExpandableListAdapter {
  public ObservableArrayList&lt;Participant&gt; list;
  @Override
  public View getGroupView(..)
  ParticipantListItemBinding binding = DataBindingUtil.inflate(inflater,R.layout.participant_list_item, parent, false);
  binding.setParticipant(list.get(groupposition));
  return binding.getRoot();
  }
  @Override 
  public View getChildView(..) {
  DrinkListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.drink_list_item, parent, false);
  binding.setDrink(list.get(goupposition).DrinkList.get(childposition));
  return binding.getRoot();
  }
  </code></pre>
  
  <p>I have 2 more xml LayoutFiles with data binding layout.drink_list_item + layout.participant_list_item which are bound to the participant and to the drink class.</p>
  
  <p>I skipped a lot of code which is not really important here.
  All is working fine except that I have a button in my layout.participant_list_item which will open a new activity where I can add a new drink to my drinklist in my dataclasses. When I finish the activity a new child should be added to the group. But it will only show after I collapse and expands the group once. Usually databinding does this for me when I call NotifyPropertychanged for a @Bindable field or if I add a new item to a directly bound ObservableArrayList. But this is not the case. I add an item to an ObservableArrayList of an item in an ObservableArrayList. Is there a way to refresh only the children of that group? Or is my approach somehow wrong?</p>
  
  <p>My dirty solution is at the moment that I tell my main binding of the activity in its onResume event that if a certain condition is met, that it should refresh all bindings which leads to a complete redraw of the ExpandableListView Activity and all items will be collapsed again (which is not a desired behavior).</p>
  
  <p>I wrote all the code from my memory since I m not at my development place at moment. But this problem bothers me since days and I could not find a decent example of Databinding and ExpandableListView so far. If you need more information just ask.</p>
  
  <p>I am glad for any hints which helps me to find a nice solution.</p>
  
  <p>This is my first question here so please be kind if the post is not meeting all the requirements.</p>
  
  <p>Thank you in advance</p>
  
  <p>//Edit. Edited some Code. Is anybody here that has any helpful comment? Do you need more code or how can I get some tips..</p>