How to get the total of a table and a list?

1

I'm making an expense application and I want my shopping list to have a total of purchases and that every time I add a new purchase the total is modified.

Here my layout:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/fondo31"
    android:scaleType="centerCrop"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#d82b2d2d">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="LISTA DE COMPRAS"
    android:background="@android:color/transparent"
    android:textColor="#fff"
    android:layout_marginTop="40dp"
    android:layout_marginBottom="30dp"
    android:textSize="20sp"
    android:textStyle="bold" />

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="wrap_content"

    tools:context="com.controlsangre.sangre.BuscarPersona">


    <ListView
        android:id="@+id/lista"
        android:layout_width="wrap_content"
        android:layout_height="349dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="15dp"
        android:background="@drawable/listaas"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:textColor="#fff"
        android:textColorHint="#ccc" />

</RelativeLayout>
    <TextView
        android:id="@+id/suma"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TOTAL: "/>
</LinearLayout>

Java Code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lista);
    lv=(ListView)findViewById(R.id.lista);

    setupActionBar();




    lista = llenar_lv();
    String[] arr={"Item1","Item2"};
    adaptador=new ArrayAdapter<String>(this, R.layout.style, lista);
    lv.setAdapter(adaptador);
}


private void setupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar !=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

public ArrayList llenar_lv() {
    ArrayList<String> lista= new ArrayList<>();
    ConexionSQLiteHelper conn=new ConexionSQLiteHelper(getApplicationContext(),"bd_usuarios",null,1);
    SQLiteDatabase database = conn.getWritableDatabase();
    String q="SELECT * FROM "+Utilidades.TABLA_COSTOS+"";
    Cursor registros =database.rawQuery(q,null);
    if (registros.moveToFirst()){
        do {

            lista.add(registros.getString(0)+"      "+registros.getString(1)+"          $"+registros.getString(2));

        }while (registros.moveToNext());
    }

    return lista;
}
    
asked by Monica 09.12.2018 в 02:14
source

0 answers