I'm populating a ListView with several items using a custom adapter.
The way I do it is like this:
AdapterDetalleVentas = new adapterDetalleVentas(actDetalleVenta, listaDetalleDeVentas);
lvPagosActDetalleVenta.setAdapter(AdapterDetalleVentas);
Where:
private static List<DetalleVenta> listaDetalleDeVentas;
private adapterDetalleVentas AdapterDetalleVentas;
private class adapterDetalleVentas extends ArrayAdapter<DetalleVenta> {
Context context;
List<DetalleVenta> detallesVentas;
public adapterDetalleVentas(Context context, List<DetalleVenta> detallesVentas) {
super(context, 0, detallesVentas);
this.context = context;
this.detallesVentas = detallesVentas;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DetalleVenta detalleVenta = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.fila_doble_horizontal, null, false);
}
TextView tvNombre = (TextView) convertView.findViewById(R.id.tvNombreFilaDobleHorizontal);
TextView tvCantidad = (TextView) convertView.findViewById(R.id.tvCantidadFilaDobleHorizontal);
tvNombre.setText(detalleVenta.getNombre());
tvCantidad.setText(String.valueOf(detalleVenta.getCantidad()));
return convertView;
}
}
fila_doble_horizontal is written as follows:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/tvNombreFilaDobleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nombre"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25px"
android:layout_weight="0.85"/>
<TextView
android:id="@+id/tvCantidadFilaDobleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Cantidad"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25px"
android:layout_weight="0.15"/>
</LinearLayout>
And it should look like this:
But when it runs the application looks like this:
Where the Ca and Calzado are for TextView tvNombre, the numbers 4 and 23 are for the TextView tvCantidad.
This is similar to that I'm not using weightSum and layout_weight :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tvNombreFilaDobleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nombre"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25px"/>
<TextView
android:id="@+id/tvCantidadFilaDobleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Cantidad"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25px"/>
</LinearLayout>
Any suggestion or idea on how to solve this?