-1

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:

enter image description here

But when it runs the application looks like this:

enter image description here

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>

enter image description here

Any suggestion or idea on how to solve this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Fabián Romo
  • 319
  • 2
  • 14

1 Answers1

0

Thanks to the people who have answered this thread.

This I also tried but the problem continued:

<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="0dp"
    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="0dp"
    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>

The problem was in the layout where the ListView was:

Originally it was like this:

   <ListView
   android:id="@+id/lvPagosActDetalleVenta"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginLeft="8px"
                android:layout_marginRight="8px">
            </ListView>

The solution was to change android:layout_width="wrap_content" to android:layout_width="match_parent" on lvPagosActDetalleVenta.

Fabián Romo
  • 319
  • 2
  • 14