title: Android Databinding in ExpandableListView
body: <p>I have a problem in expandableListView that is weird with databinding.There is textview of quantity which can be incremented/decremented on button click.The Textview correctly updates at specific position. But when scrolled down the value changes the to textview at different position. Also , when group expanded  value move the below item textview.Below are adapter , xml and model class.</p>
  
  <pre><code>public class ProductExpandableListAdapter extends BaseExpandableListAdapter {
  
      private Activity contextActivity;
      private ArrayList&lt;ProductItems&gt; productItemsArrayList;
  
      public ProductExpandableListAdapter(ProductActivity productActivity, ArrayList&lt;ProductItems&gt; productItemsArrayList) {
          this.contextActivity = productActivity;
          this.productItemsArrayList = productItemsArrayList;
      }
  
      @Override
      public void registerDataSetObserver(DataSetObserver dataSetObserver) {
  
      }
  
  
      @Override
      public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
  
      }
  
      @Override
      public int getGroupCount() {
          return this.productItemsArrayList.size();
      }
  
      @Override
      public int getChildrenCount(int i) {
          return 1;
      }
  
      @Override
      public Object getGroup(int i) {
          return this.productItemsArrayList.get(i);
      }
  
      @Override
      public Object getChild(int i, int i1) {
          return this.productItemsArrayList.get(i).getProductItemDescription();
  
      }
  
  
      @Override
      public long getGroupId(int i) {
          return i;
      }
  
      @Override
      public long getChildId(int i, int i1) {
          return i1;
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
      @Override
      public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
          final ProductItems productItems = productItemsArrayList.get(i);
          if (view == null) {
              LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
              final ProductItemBinding productItemsBinding = DataBindingUtil.inflate(layoutInflater, R.layout.product_items, viewGroup, false);
              HelveticaNeueFontHelper.applyHelveticaneuemedFont(contextActivity, productItemsBinding.productTitleTextView);
              productItemsBinding.productTitleTextView.setTextSize(contextActivity.getResources().getDimension(R.dimen.dim_64_pt));
              view = productItemsBinding.getRoot();
              HelveticaNeueFontHelper.applyHelveticaneuemedFont(contextActivity, productItemsBinding.productPriceTextView);
              productItemsBinding.productPriceTextView.setTextSize(contextActivity.getResources().getDimension(R.dimen.dim_72_pt));
              HelveticaNeueFontHelper.applyHelveticaneuemedFont(contextActivity, productItemsBinding.qtyTextView);
              productItemsBinding.qtyTextView.setTextSize(contextActivity.getResources().getDimension(R.dimen.dim_104_pt));
              productItemsBinding.setHandler(new QuantityHandler() {
                  @Override
                  public void onQuantityIncrement() {
                      changeQuantity(productItemsBinding, productItems, productItems.getProductItemQty(), Constants.ADDITION);
                      Toast.makeText(contextActivity, "quantityIncrement : ", Toast.LENGTH_LONG).show();
                  }
  
                  @Override
                  public void onQuantityDecrement() {
                      changeQuantity(productItemsBinding, productItems, productItems.getProductItemQty(), Constants.SUBTRACTION);
                      Toast.makeText(contextActivity, "quantityDecrement : ", Toast.LENGTH_LONG).show();
                  }
              });
              productItemsBinding.setProductItems(productItems);
  
          }
          return view;
      }
  
  
      @Override
      public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
  
          if (view == null) {
              LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
              final ProductItemsChildBinding productItemsChildBinding = DataBindingUtil.inflate(layoutInflater, R.layout.product_items_child, viewGroup, false);
              HelveticaNeueFontHelper.applyHelveticaneuelightFont(contextActivity, productItemsChildBinding.productDescriptionTextView);
              productItemsChildBinding.productDescriptionTextView.setTextSize(contextActivity.getResources().getDimension(R.dimen.dim_64_pt));
              productItemsChildBinding.setProductItems(productItemsArrayList.get(i));
              view = productItemsChildBinding.getRoot();
          }
          return view;
      }
  
      @Override
      public boolean isChildSelectable(int i, int i1) {
          return true;
      }
  
      @Override
      public boolean areAllItemsEnabled() {
          return false;
      }
  
      @Override
      public boolean isEmpty() {
          return false;
      }
  
      @Override
      public void onGroupExpanded(int i) {
      }
  
      @Override
      public void onGroupCollapsed(int i) {
  
      }
  
      @Override
      public long getCombinedChildId(long l, long l1) {
          return 0;
      }
  
      @Override
      public long getCombinedGroupId(long l) {
          return 0;
      }
  
  
      private void changeQuantity(final ProductItemBinding productItemsBinding, ProductItems productItems, ObservableInt observableIntQty, String operand) {
  
  
          switch (operand) {
              case Constants.ADDITION:
                  if (observableIntQty.get() &gt;= 0) {
                      observableIntQty.set(observableIntQty.get() + 1);
                  }
                  break;
              case Constants.SUBTRACTION:
                  if (observableIntQty.get() &gt; 0) {
                      observableIntQty.set(observableIntQty.get() - 1);
                  }
                  break;
  
          }
  
          contextActivity.runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  productItemsBinding.executePendingBindings();
              }
          });
  
  
      }
  
  
  }
  </code></pre>
  
  <p> </p>
  
  <pre><code>&lt;data class="ProductItemBinding"&gt;
  
      &lt;variable
          name="productItems"
          type="com.vtrio.waterapp.data.ProductItems" /&gt;
  
      &lt;variable
          name="handler"
          type="com.vtrio.waterapp.listeners.QuantityHandler" /&gt;
  
  &lt;/data&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:background="@drawable/rounded_corner_bluegradient"
      android:gravity="center_vertical"
      android:orientation="horizontal"
      android:weightSum="1"&gt;
  
  
      &lt;ImageView
          android:id="@+id/productImageView"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="0.3"
          app:imgSrc="@{productItems.productItemImage}" /&gt;
  
  
      &lt;LinearLayout
          android:id="@+id/productInfoLinearLayout"
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_gravity="center_vertical"
          android:layout_weight="0.45"
          android:gravity="center_vertical"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/productTitleTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@{productItems.productItemTitleName}" /&gt;
  
  
          &lt;TextView
              android:id="@+id/productPriceTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@{productItems.productItemPrice}" /&gt;
  
      &lt;/LinearLayout&gt;
  
  
      &lt;RelativeLayout
          android:id="@+id/quantityModRelativeLayout"
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_marginEnd="10dp"
          android:layout_marginRight="10dp"
          android:layout_weight="0.25"
          android:gravity="center"&gt;
  
  
          &lt;Button
              android:id="@+id/subtractQtyButton"
              android:layout_width="25dp"
              android:layout_height="25dp"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
              android:background="@color/addsubColor"
              android:focusable="false"
              android:focusableInTouchMode="false"
              android:onClick="@{(v) -&gt; handler.onQuantityDecrement()}"
              android:text="@string/sub"
              android:textColor="@color/addsubTextColor" /&gt;
  
  
          &lt;TextView
              android:id="@+id/qtyTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerHorizontal="true"
              android:text="@{Integer.toString(productItems.productItemQty)}" /&gt;
  
          &lt;Button
              android:id="@+id/addQtyButton"
              android:layout_width="25dp"
              android:layout_height="25dp"
              android:layout_alignParentEnd="true"
              android:layout_alignParentRight="true"
              android:background="@color/addsubColor"
              android:focusable="false"
              android:focusableInTouchMode="false"
              android:onClick="@{(v) -&gt; handler.onQuantityIncrement()}"
              android:text="@string/add"
              android:textColor="@color/addsubTextColor" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  
  &lt;/LinearLayout&gt; &lt;/layout&gt;
  </code></pre>
  
  <p>ProductItems </p>
  
  <pre><code>public class ProductItems extends BaseObservable {
  
      private String productItemTitleName;
      private String productItemPrice;
      private int productItemImage;
      private String productItemDescription;
      private ObservableInt productItemQty;
      private ArrayList&lt;ProductItems&gt; cartItem;
  
  
      public ProductItems(String productItemTitleName, String productItemPrice, int productItemImage, String productItemDescription, ObservableInt productItemQty) {
          this.productItemTitleName = productItemTitleName;
          this.productItemPrice = productItemPrice;
          this.productItemImage = productItemImage;
          this.productItemDescription = productItemDescription;
          this.productItemQty = productItemQty;
      }
  
  
      public String getProductItemTitleName() {
          return productItemTitleName;
      }
  
      public void setProductItemTitleName(String productItemTitleName) {
          this.productItemTitleName = productItemTitleName;
      }
  
      public String getProductItemPrice() {
          return productItemPrice;
      }
  
      public void setProductItemPrice(String productItemPrice) {
          this.productItemPrice = productItemPrice;
      }
  
      public int getProductItemImage() {
          return productItemImage;
      }
  
      public void setProductItemImage(int productItemImage) {
          this.productItemImage = productItemImage;
      }
  
      public String getProductItemDescription() {
          return productItemDescription;
      }
  
      public void setProductItemDescription(String productItemDescription) {
          this.productItemDescription = productItemDescription;
      }
  
      @Bindable
      public ObservableInt getProductItemQty() {
          return productItemQty;
  
      }
  
  
      public void setProductItemQty(ObservableInt productItemQty) {
          this.productItemQty = productItemQty;
          notifyPropertyChanged(BR.productItemQty);
  
      }
  </code></pre>
  
  <p>What is the problem and what can be done to solve this.</p>