Cómo dividir anidados ArrayList a todos los diseños en TabLayout

Estoy utilizando anidados ArrayList para Tablayout. Cada elemento de ArrayList llena cada ficha. El recuento de fichas cambia según el tamaño del arraylist padre. Por ejemplo Cuando el tamaño de ArrayList padre 2, el recuento de fichas 2; Cuando el tamaño 3 tabulación cuenta 3..etc .. A fin de explicar esta situación es difícil, he preparado expalantion imagen ..

Imagen 1

Esta imagen representa la apariencia general. Quiero rellenar este TextViews con ArrayLists cada elemento

Imagen 2

Esta imagen representa mi tipo de datos; Claves y valores ArrayList es arraylist anidado y contienen arraylist en cada índice.

Imagen 3 – Imagen 4 – Imagen 5

Estas imágenes representan cómo usaba tabLayouts. Quiero que mis datos se parezcan a estas imágenes.

Así que la cuestión es PopUpDetailsAdapterPlanT Clase;

Cuando utilizo los códigos debajo de cada fila pueblan con el mismo artículo. Para este ejemplo cada fila escribe el último elemento de ArrayList ( Location – Minnesota ) Cómo puedo manejar este problema. Gracias por ayuda

public class PopUpDetailsAdapterPlanT extends ArrayAdapter { Context context; private ArrayList<ArrayList<Object>> keys; private ArrayList<ArrayList<String>> values; public PopUpDetailsAdapterPlanT(Context context, ArrayList<ArrayList<Object>> keys, ArrayList<ArrayList<String>> values) { super(context,R.layout.popupdetails_listview_simpleitem); this.keys = keys; this.values = values; this.context = context; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.popupdetails_listview_simpleitem, null); } TextView tv1 = (TextView) v.findViewById(R.id.hashmapKeys); TextView tv2 = (TextView) v.findViewById(R.id.hashmapValues); for (int i = 0; i < keys.size(); i++) { ArrayList<Object> mKeys = new ArrayList<>(keys.get(i)); ArrayList<String> mValues = new ArrayList<>(values.get(i)); for (int j = 0; j <mKeys.size() ; j++) { tv1.setText(String.valueOf(mKeys.get(j))); tv2.setText(String.valueOf(mValues.get(j))); } } return v; } @Override public int getCount() { return keys.get(0).size(); } @Override public Object getItem(int position) { if (position >= keys.size()) return values.get(position); return keys.get(position); } } 

Introduzca aquí la descripción de la imagen

Espero que entienda sus requisitos y código correctamente. Entiendo que solo tienes 2 TextViews en el diseño para 10 textos diferentes. Así que … en este caso, necesitas 10 TextViews para el ObjectID, fila #, nombre, edad, apellido, ubicación, etc. No puedes tener solo 2 TextViews.

Empecemos con esto y espero que los problemas se aclararán para todos nosotros.

Si puede pasar el índice de la ficha relevante al adaptador de cada fragmento. Puede cambiar el adaptador del fragmento como se indica a continuación y probar:

 public class PopUpDetailsAdapterPlanT extends ArrayAdapter { Context context; private ArrayList<Object> keys; private ArrayList<String> values; public PopUpDetailsAdapterPlanT(Context context, ArrayList<ArrayList<Object>> keys, ArrayList<ArrayList<String>> values, int tabIndex) { super(context,R.layout.popupdetails_listview_simpleitem); this.keys = keys.get(tabIndex); this.values = values.get(tabIndex); this.context = context; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.popupdetails_listview_simpleitem, null); } TextView tv1 = (TextView) v.findViewById(R.id.hashmapKeys); TextView tv2 = (TextView) v.findViewById(R.id.hashmapValues); tv1.setText(String.valueOf(keys.get(position))); tv2.setText(String.valueOf(values.get(position))); return v; } @Override public int getCount() { return keys.size(); } @Override public Object getItem(int position) { if (position >= keys.size()) return values.get(position); return keys.get(position); } } 

Estoy sugiriendo una estructura de datos diferente para usted, basada en sus comentarios en el problema publicado. Código de muestra:

 private ArrayList<Integer> keys; private ArrayList<Person> values; 

Notas:

  • Las claves de objeto contienen las ID de clave principal.
  • Los valores de objeto contienen una clase, yo la llamo Person. Persona es una clase que contiene nombre, apellido, edad y ubicación. La clase tiene la flexibilidad de agregar otro atributo.

Si este diseño parece adecuado para usted, entonces podemos discutirlo con más detalles.

  • Artículos OnCreateContextMenu y ListView
  • Envío de la lista de objetos del array entre actividades con Parcelable
  • Cómo configurar los datos de ArrayList en ListView?
  • No se puede ordenar la lista por orden ascendente
  • Rendimiento de bucle ArrayList en ART (Android Runtime Environment)
  • ArrayList indexOf () devuelve índice incorrecto?
  • ¿Cómo puedo convertir String a ArrayList <String>
  • ¿Cuál es la manera más eficiente de ordenar simultáneamente tres ArrayLists en Java
  • Insertar matriz en la base de datos SQLite en android
  • No se pueden eliminar elementos duplicados de arraylist de hashmap
  • ¿Cuál es la mejor manera de guardar el contenido de una ArrayList?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.