ListView with Object Vector

0

You see, I have an ArrayList called List, which stores a list of elements, such as strings of characters.

The main XML:

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

The XML of the template:

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/caja"
    >

</TextView>

And the java code:

String[] nombres={"Juan", "Pedro", "Ana", "Luis" };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listado);

        ArrayAdapter adaptado=new ArrayAdapter<String>(this,R.layout.plantilla,nombres);
        setListAdapter(adaptado);
    }

However, I'm not interested in storing a String vector, but the ArrayList of an object named Persona:

public class Persona{
    public String nombre;
    public String apellidos;
    public int edad;
    public boolean casado;
    public boolean antecedente;
    public boolean hijos;

    public Persona(String n, String a, int e, boolean c, boolean p, boolean h){
        nombre=n;
        apellidos=a;
        edad=e;
        casado=c;
        antecedente=p;
        hijos=h;
    }

    public String boda(){
        if(casado)
            if(hijos)
            return "Esta casado y tiene hijos";
            else
                return "Esta casado";
        else
            return "Es soltero";
    }

    public String penal(){
        if(antecedente)
            return "Tiene antecedentes penales";
        else
            return "No tiene antecedentes penales";
    }
}

It would be the variable like this:

ArrayList<Persona> lista=new ArrayList<>();

How do you do a ListView that shows the person's data?

    
asked by Miguel Alparez 01.03.2018 в 22:23
source

0 answers