title: How to update total price in cart listview in android
body: <p>I have a <code>ListView</code> which displays items in my shopping cart from my existing database and at the bottom i have created <code>TextView</code> of total price of all the items in my cart,but the total price that displays at the bottom does not get updated according to the products in my cart.I am not getting where am I making mistake,please help me out.</p>
  
  <p>xml code for <code>TextView</code> of Total price:</p>
  
  <pre><code>    &lt;TextView
          android:id="@+id/totalItemPrice"
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:text="RS "
          android:textSize="20dp"
          android:layout_marginLeft="15dp"
          android:layout_marginTop="20dp"
          android:textColor="#FFFFFF"/&gt;
  </code></pre>
  
  <p><strong>AddToCartFragment.java :</strong></p>
  
  <pre><code>private ArrayList&lt;GenieCart_List_Model&gt; mAddList;
  
  private void getCart_Data() {
      try {
              db = new DataBasehelper1(getActivity());
              mAddList = new ArrayList&lt;GenieCart_List_Model&gt;();
              mAddList = db.getAllCotacts();
              long sum = db.sum_Of_Rs();
              mTotalItemPrice.setText("Total Rs : " + sum);
              db.close();
          }
      catch (Exception e) {
              e.printStackTrace();
          }
    }
  </code></pre>
  
  <p><strong>DataBaseHelper1.java:</strong></p>
  
  <pre><code>public long sum_Of_Rs() {
       SQLiteDatabase db = this.getReadableDatabase();
        Cursor res = db.rawQuery(" select * from  " +CONTACTS_TABLE_NAME + " ORDER BY " + CONTACTS_PRODUCT_ID + " DESC " , null);
      ArrayList&lt;GenieCart_List_Model&gt; list = new ArrayList&lt;GenieCart_List_Model&gt;();
      try {
  
          res.moveToFirst();
  
          for (int i = 0; i &lt; res.getCount(); i++) {
  
              GenieCart_List_Model Prod_Details = new GenieCart_List_Model();
              Prod_Details.setPrice(res.getString(res.getColumnIndex(CONTACTS_PRODUCT_RS)));
              Prod_Details.setProdID(res.getString(res.getColumnIndex(CONTACTS_PRODUCT_ID)));
  
              try {
                  int total = Integer.parseInt(res.getString(res.getColumnIndex(CONTACTS_PRODUCT_RS)));
  
                  Sum = Sum + total;
                  return Sum;
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              list.add(Prod_Details);
              res.moveToNext();
          }
  
      }
      catch (Exception e) {
          e.printStackTrace();
      }
      return Sum;
  }
  </code></pre>