title: Android RecyclerView - Calculate items
body: <p>I'm developing an Android project and I've created a <code>RecyclerView</code> - <code>CardView</code>.</p>
  
  <p>The app is going to look like as the image below. </p>
  
  <p><a href="https://i.stack.imgur.com/hfCYC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hfCYC.png" alt="App Image"></a></p>
  
  <p>The app is running, but I'm having trouble calculating some numbers after I've input some data.</p>
  
  <p>I need to:</p>
  
  <ul>
  <li>as I insert the data, the app shows the value of the multiplication of <strong>"Quantidade"</strong> field and the <strong>"Valor Unitário"</strong> field on the <code>TextView</code> that is under the <strong>"Valor Total"</strong>.</li>
  </ul>
  
  <p>How do I do such thing?</p>
  
  <p>The codes are here:
  MainActivity.java</p>
  
  <pre><code>package com.example.rooseveltjunior.gastosrestaurante;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          RecyclerView recList = (RecyclerView) findViewById(R.id.listaGastos);
          recList.setHasFixedSize(true);
          LinearLayoutManager llm = new LinearLayoutManager(this);
          llm.setOrientation(LinearLayoutManager.VERTICAL);
          recList.setLayoutManager(llm);
  
          GastosAdaptador ga = new GastosAdaptador(creatList(3));
          recList.setAdapter(ga);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
  
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      private List&lt;GastosInfo&gt; creatList(int size) {
  
          List&lt;GastosInfo&gt; result = new ArrayList&lt;GastosInfo&gt;();
          for (int i = 1; i &lt; size; i++) {
              GastosInfo ci = new GastosInfo();
              ci.descricao = GastosInfo.DESCRICAO_PREFIX;
              ci.quantidade = GastosInfo.QUANTIDADE_PREFIX;
              ci.valor_unitario = GastosInfo.VALOR_UNITARIO_PREFIX;
              ci.valor_total = GastosInfo.VALOR_TOTAL_PREFIX;
  
              ci.qnt = GastosInfo.Qnt_Prefix;
              ci.val_unit = GastosInfo.Val_Unit_Prefix;
              ci.val_tot = GastosInfo.Qnt_Prefix + GastosInfo.Val_Unit_Prefix;
  
              result.add(ci);
          }
          return result;
      }
  }
  </code></pre>
  
  <p>Data</p>
  
  <pre><code>package com.example.rooseveltjunior.gastosrestaurante;
  
  /**
   * Created by Roosevelt.junior on 18/11/2015.
   */
  class GastosInfo {
  
      String descricao;
      String quantidade;
      String valor_unitario;
      String valor_total;
      int qnt;
      int val_unit;
      int val_tot;
  
      static final String DESCRICAO_PREFIX = "Item ";
      static final String QUANTIDADE_PREFIX = "Quantidade: ";
      static final String VALOR_UNITARIO_PREFIX = "Valor Unitário: ";
      static final String VALOR_TOTAL_PREFIX = "Valor Total";
      static final int Qnt_Prefix = 0;
      static final int Val_Unit_Prefix = 0;
  
  }
  </code></pre>
  
  <p>Adapter</p>
  
  <pre><code>package com.example.rooseveltjunior.gastosrestaurante;
  
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import java.util.List;
  
  /**
   * Created by Roosevelt.junior on 18/11/2015.
   */
  public class GastosAdaptador extends RecyclerView.Adapter&lt;GastosAdaptador.GastosViewHolder&gt; {
  
      private List&lt;GastosInfo&gt; gastosLista;
  
      public GastosAdaptador(List&lt;GastosInfo&gt; gastosLista){
  
          this.gastosLista = gastosLista;
      }
  
      @Override
      public GastosViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          View itemView = LayoutInflater.
                  from(viewGroup.getContext()).
                  inflate(R.layout.card_gastos,viewGroup,false);
          return new GastosViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(GastosViewHolder gastosViewHolder, int i) {
          GastosInfo ci = gastosLista.get(i);
          gastosViewHolder.vDescricao.setText(ci.descricao);
          gastosViewHolder.vQuantidade.setText(ci.quantidade);
          gastosViewHolder.vValorUnitario.setText(ci.valor_unitario);
          gastosViewHolder.vValorTotal.setText(ci.valor_total);
      }
  
      @Override
      public int getItemCount() {
          return gastosLista.size();
      }
  
      public static class GastosViewHolder extends RecyclerView.ViewHolder {
  
          TextView vDescricao;
          TextView vQuantidade;
          TextView vValorUnitario;
          TextView vValorTotal;
          EditText vQnt;
          EditText vValUnit;
          TextView vValTot;
  
          public GastosViewHolder (View v){
              super(v);
              vDescricao = (TextView) v.findViewById(R.id.txtDescricao);
              vQuantidade = (TextView) v.findViewById(R.id.txtQuantidade);
              vValorUnitario = (TextView) v.findViewById(R.id.txtValorUnitario);
              vValorTotal = (TextView) v.findViewById(R.id.txtValorTotal);
              vQnt= (EditText) v.findViewById(R.id.txtEditQnt);
              vValUnit = (EditText) v.findViewById(R.id.txtEditUnit);
              vValTot = (TextView) v.findViewById(R.id.txtTotal);
  
          }
      }
  }
  </code></pre>