ArrayList ArrayList in a GridView

0

What kind of friends, I need help to create a GridView in android studio just that I have to format it vertically, well I explain myself better.

my database brings me 12 elements and what I do is add it to a ArrayList<String> and the logic that has the GridView is the result in a row and I need it this way

 
    1 | 3 | 5 | 7 | 9  | 11
    2 | 4 | 6 | 8 | 10 | 12

and the grid accommodates them consecutively. Example

 1 | 2 | 3 | 4  | 5  | 6  
 7 | 8 | 9 | 10 | 11 | 12

I have a adapter to create the format as I want it, I leave my code

@Override
public View getView(int i, View view, ViewGroup viewGroup) {

    int contador = 0;
    if(view == null)
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.activity_tickets_gridaviewadapter, null);

    }

    TextView txtPuntoUp, txtPuntoBottom;
    txtPuntoUp = (TextView) view.findViewById(R.id.txtPunto_top);
    txtPuntoBottom = (TextView) view.findViewById(R.id.txtPunto_bottom);

    txtPuntoUp.setText(arrayList.get(i));
    txtPuntoBottom.setText(arrayList.get(i+1));

    return view;
}

and so I generate the arrangement

public void ObtenerRegistros()
{
    try {
        Statement statement = conexion().createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT vchNombre, iidDispensario FROM catPuntoCarga");
        while (resultSet.next())
        {
            Toast.makeText(getApplicationContext(), resultSet.getString("vchNombre"), Toast.LENGTH_SHORT).show();
            listaPuntos.add(resultSet.getString("vchNombre"));
        }
    }
    catch (Exception e)
    {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

I do not know if I explained myself well, but I will be on the lookout to be able to give a better explanation to whoever needs it.

    
asked by Luis García 06.12.2017 в 20:35
source

1 answer

0

Not tested

The arrangement of the elements in a normal way, is to fill the elements horizontally, when reaching the maximum of columCount another row is filled

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"    
        android:rowCount="2"
        android:columnCount="2">
     <TextView
            android:text="Cell 0"
            android:textSize="14dip" />
     <TextView
            android:text="Cell 1"
            android:textSize="14dip" />
     <TextView
            android:text="Cell 2"
            android:textSize="14dip" />
     <TextView
            android:text="Cell 3"
            android:textSize="14dip" />
</GridLayout>

It is shown as follows

If the property android:orientation="vertical" is set, the filling of the elements is vertical when reaching the maximum of rowCount the next column is filled

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"    
        android:rowCount="2"
        android:columnCount="2"
        android:orientation="vertical">
        ...
</GridLayout>

Extracted from here

    
answered by 06.12.2017 в 22:20