I have a generic abstract class that inherits from
BaseAdapter
and which I use to load ListView
(s) from a ArrayList
of any objects. The class works well and being abstract forces me to implement the onEntrada
method that is the one I use for each object and the new view that is filled in, that is, the mold layout to be filled in.
So far, the problem is that when I slide my finger on the tablet that I have for the tests the letters of the TextViews if they overwrite seeing the fatal thing, until I loose and return everything to its place.
I thought the problem came because the ListView calls the getView function continuously and reloads all the data, so I tried something I found around here, to create a static ViewHolder class with the Views equal to the ones I need per row and go checking that it has not been filled, but the result is the same. You see the fatal thing. I do not know if it's a problem with the Android version, the size of the Tablet, the performance (the latter misses me, it's a Samsung Galaxy of the last and it's going very well). If someone has happened or better know the solution to see if you can throw a cable. I leave the class I use as Adpater.
public abstract class Lista_adaptador extends BaseAdapter {
private ArrayList<?> entradas;
private int R_layout_IdView;
public Context getContexto() {
return contexto;
}
private Context contexto;
public Lista_adaptador(Context contexto, int R_layout_IdView, ArrayList<?> entradas) {
super();
this.contexto = contexto;
this.entradas = entradas;
this.R_layout_IdView = R_layout_IdView;
}
@Override
public View getView(int posicion, View view, ViewGroup pariente)
{View v = view;
if (v == null) {
LayoutInflater vi = LayoutInflater.from(contexto);
v = vi.inflate(R_layout_IdView, null);
}
else
{
}
onEntrada(entradas.get(posicion), v);
return v;
}
@Override
public int getCount() {
return entradas.size();
}
@Override
public Object getItem(int posicion) {
return entradas.get(posicion);
}
@Override
public long getItemId(int posicion) {
return posicion;
}
/**
* Devuelve cada una de las entradas con cada una de las vistas a la que debe de ser asociada
*
* @param entrada La entrada que será la asociada a la view. La entrada es del tipo del paquete/handler
* @param view View particular que contendrá los datos del paquete/handler
*/
public abstract void onEntrada(Object entrada, View view);
}
Thanks Einer probe v = vi.inflate (R_layout_IdView, relative, false); and the thing remains the same. I attached an image of how it looks.
The class is abstract as I say you can use any other class to load your ListView, just have an ArrayList of any objects and implement the OnEntry () Example:
Aggregated list.setAdapter (new Adapter_list (this, R.layout.linea_note, Aggregated data) {
@Override
public void onEntrada(Object entrada, View view) {
//Aquí se rellenan los views de la view de entrada.
}
One of the xml I use to inflate the cells in the lists is this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tv_refLineaNota"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Referencia"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_nombreLineaNota"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Nombre de Linea de Nota"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_cantidadlineanota"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:gravity="center"
android:paddingRight="5dp"
android:text="Cantidad"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_tipounidadLineaNota"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight="0"
android:gravity="left|center"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:text="Kg" />