Listview is not displaying anything

1

I have the class response

public class Resposta {
    private String Nome;
    private boolean Certo_Errado;

    public Resposta(String nome, boolean certo_Errado) {
        Nome = nome;
        Certo_Errado = certo_Errado;
    }

    public String getNome() {
        return Nome;
    }

    public void setNome(String nome) {
        Nome = nome;
    }

    public boolean isCerto_Errado() {
        return Certo_Errado;
    }

    public void setCerto_Errado(boolean certo_Errado) {
        Certo_Errado = certo_Errado;
    }  

The custom adapter

public class Resposta_Adapter extends ArrayAdapter<Resposta> {

    private final Context context;
    private final List<Resposta> Respostas;

    public Resposta_Adapter(Context context, List<Resposta> respostas) {
        super(context, R.layout.list_respostas);
        this.context = context.getApplicationContext();
        this.Respostas = respostas;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_respostas, parent, false);

        Resposta rsp = Respostas.get(position);

        TextView tc = view.findViewById(R.id.txt);
        tc.setText(rsp.getNome());

        return rowView;
    }
}

And in the main activity:

public class MainActivity extends AppCompatActivity {

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

        List<Resposta> oRespostas = new ArrayList<Resposta>();


        for (int i = 0; i < 5; i++) {
            boolean a = false;
            if (i == 2)
                a = true;
            else
                a = false;
            oRespostas.add(new Resposta("Resposta " + i, a));
        }

        ListView lista = (ListView) findViewById(R.id.lista);

        Resposta_Adapter adapter;
        adapter = new Resposta_Adapter(getApplicationContext(), oRespostas);

        lista.setAdapter(adapter);


    }
}

But the listview is not being filled. I can not see what may be wrong

Edit: Main screen XML: '

<TextView
    android:id="@+id/txt_Pergunta"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/Padrao"
    android:textAlignment="center"
    android:textSize="18sp"
    android:textStyle="italic" />

<ListView
    android:id="@+id/lista"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/txt_Pergunta"
    />

'

    
asked by anonymous 05.04.2018 / 18:49

1 answer

0

Try using this method for getView

@Override
public View getView(int position, View view, ViewGroup parent) {

    view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_respostas, parent, false);

    Resposta rsp = Respostas.get(position);

    TextView tc = view.findViewById(R.id.txt);
    tc.setText(rsp.getNome());

    return view;
}
    
05.04.2018 / 22:57