Variable must provide either dimension expression or an array initializer Syntax error on token, misplaced construct

0

I'm new to programming for Android and would like to fix this error:

package br.pedromazer.cantoliturgico;

import br.pedromazer.cantoliturgico.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;

public class Lista extends Activity {

    @Override
    protected void onCreate(Bundle b) {
        // TODO Auto-generated method stub
        super.onCreate(b);
        setContentView(R.layout.lista);

        btnVoltar = (ImageButton) this.findViewById(R.id.btnVoltar);
        btnVoltar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //Ao invés de trabalhar aqui, criar um evento cf. acima do ImageButton
                //Aqui chama o método com um evento
                btnVoltar_onClick(v);
            }
        });

        lstAlunos = (ListView) this.findViewById(R.id.lstAlunos);

        ArrayAdapter<string> array = new
            ArrayAdapter<string> (this, android.R.layout.simple_list_item_single_choice), alunos;

        lstAlunos.setAdapter(array);

        lstAlunos.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                lstView_onClick(v);
            }
        });

    }

    public void btnVoltar_onClick(View v) {

        this.finish();

    }

    public void lstView_onClick(View v) {

        Intent i = new Intent(this, Lista.class);
        this.startActivity(i);

    }

    String[] alunos = ***new String[]***("Aluno A", "Aluno B", "Aluno C");
    ImageButton btnVoltar;
    ListView lstAlunos;

}
    
asked by anonymous 20.08.2014 / 04:02

1 answer

1

Stacked!

In any case try this:

    String[] alunos = new String[] {"Aluno 1", "Aluno 2", "Aluno 3"};

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, alunos);

    ListView listView = (ListView)findViewById(R.id.lstAlunos);

    listView.setAdapter(arrayAdapter);
    
20.08.2014 / 04:40