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.