From 4340a85686acd421ec6b9a92e4e9a5b21d159b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Cort=C3=A9s?= Date: Fri, 22 Nov 2019 18:31:35 -0300 Subject: [PATCH] Quedo mas bonita ahora :3 --- .../androidsqlite/AddProductoActivity.java | 2 +- .../androidsqlite/CustomAdapter.java | 11 ++-- .../GetAllProductosActivity.java | 9 ++- .../androidsqlite/UpdateDeleteActivity.java | 2 +- .../main/res/layout/activity_add_producto.xml | 47 ++++++++++--- .../res/layout/activity_get_all_productos.xml | 5 ++ .../res/layout/activity_update_delete.xml | 52 ++++++++++++--- app/src/main/res/layout/list_view.xml | 66 +++++++++---------- app/src/main/res/values/styles.xml | 1 - 9 files changed, 137 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/xyz/danielcortes/androidsqlite/AddProductoActivity.java b/app/src/main/java/xyz/danielcortes/androidsqlite/AddProductoActivity.java index 823241f..9648ea3 100755 --- a/app/src/main/java/xyz/danielcortes/androidsqlite/AddProductoActivity.java +++ b/app/src/main/java/xyz/danielcortes/androidsqlite/AddProductoActivity.java @@ -30,7 +30,7 @@ public class AddProductoActivity extends AppCompatActivity { grabarButton = findViewById(R.id.grabarButton); nombreText = findViewById(R.id.nombreText); cantidadText = findViewById(R.id.cantidadText); - precioText = findViewById(R.id.precioText); + precioText = findViewById(R.id.totalText); grabarButton.setOnClickListener(onSave()); } diff --git a/app/src/main/java/xyz/danielcortes/androidsqlite/CustomAdapter.java b/app/src/main/java/xyz/danielcortes/androidsqlite/CustomAdapter.java index 735ac96..c5862cb 100755 --- a/app/src/main/java/xyz/danielcortes/androidsqlite/CustomAdapter.java +++ b/app/src/main/java/xyz/danielcortes/androidsqlite/CustomAdapter.java @@ -7,6 +7,7 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; +import java.text.NumberFormat; import java.util.List; public class CustomAdapter extends BaseAdapter { @@ -48,8 +49,8 @@ public class CustomAdapter extends BaseAdapter { view = inflater.inflate(R.layout.list_view, null, true); viewHolder.nombreText = view.findViewById(R.id.nombreText); viewHolder.cantidadText = view.findViewById(R.id.cantidadText); - viewHolder.precioText = view.findViewById(R.id.precioText); viewHolder.totalText = view.findViewById(R.id.totalText); + viewHolder.precioText = view.findViewById(R.id.precioText); view.setTag(viewHolder); }else{ viewHolder = (ViewHolder)view.getTag(); @@ -57,10 +58,12 @@ public class CustomAdapter extends BaseAdapter { Producto producto = productos.get(i); - viewHolder.nombreText.setText("Nombre: " + producto.getNombre()); + viewHolder.nombreText.setText(producto.getNombre()); viewHolder.cantidadText.setText("Cantidad: " + producto.getCantidad()); - viewHolder.precioText.setText("Precio: " + producto.getPrecio()); - viewHolder.totalText.setText("Total: " + (producto.getPrecio() * producto.getCantidad())); + + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + viewHolder.precioText.setText(formatter.format(producto.getPrecio())); + viewHolder.totalText.setText(formatter.format(producto.getCantidad() * producto.getPrecio())); return view; } diff --git a/app/src/main/java/xyz/danielcortes/androidsqlite/GetAllProductosActivity.java b/app/src/main/java/xyz/danielcortes/androidsqlite/GetAllProductosActivity.java index b249bb2..74ca0a4 100755 --- a/app/src/main/java/xyz/danielcortes/androidsqlite/GetAllProductosActivity.java +++ b/app/src/main/java/xyz/danielcortes/androidsqlite/GetAllProductosActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -12,6 +13,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; +import java.text.NumberFormat; import java.util.List; public class GetAllProductosActivity extends AppCompatActivity { @@ -36,7 +38,9 @@ public class GetAllProductosActivity extends AppCompatActivity { productos = databaseHelper.getAllProductos(); customAdapter = new CustomAdapter(this, productos); listView.setAdapter(customAdapter); - totalText.setText("Total: " + databaseHelper.getTotal()); + + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + totalText.setText("Total: " + formatter.format(databaseHelper.getTotal())); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -62,6 +66,7 @@ public class GetAllProductosActivity extends AppCompatActivity { productos = databaseHelper.getAllProductos(); customAdapter.changeList(productos); customAdapter.notifyDataSetChanged(); - totalText.setText("Total: " + databaseHelper.getTotal()); + NumberFormat formatter = NumberFormat.getCurrencyInstance(); + totalText.setText("Total: " + formatter.format(databaseHelper.getTotal())); } } diff --git a/app/src/main/java/xyz/danielcortes/androidsqlite/UpdateDeleteActivity.java b/app/src/main/java/xyz/danielcortes/androidsqlite/UpdateDeleteActivity.java index 2ca612a..7812a88 100755 --- a/app/src/main/java/xyz/danielcortes/androidsqlite/UpdateDeleteActivity.java +++ b/app/src/main/java/xyz/danielcortes/androidsqlite/UpdateDeleteActivity.java @@ -34,7 +34,7 @@ public class UpdateDeleteActivity extends AppCompatActivity { databaseHelper = new DatabaseHelper(this); nombreText = findViewById(R.id.nombreText); - precioText = findViewById(R.id.precioText); + precioText = findViewById(R.id.totalText); cantidadText = findViewById(R.id.cantidadText); updateButton = findViewById(R.id.updateButton); diff --git a/app/src/main/res/layout/activity_add_producto.xml b/app/src/main/res/layout/activity_add_producto.xml index ddf9547..150a598 100755 --- a/app/src/main/res/layout/activity_add_producto.xml +++ b/app/src/main/res/layout/activity_add_producto.xml @@ -11,42 +11,43 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:layout_marginTop="16dp" + android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:ems="10" android:hint="Nombre" android:inputType="text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/textView" /> + app:layout_constraintTop_toBottomOf="@+id/textView2" /> + app:layout_constraintTop_toBottomOf="@+id/textView3" />