I'm starting now with Android development. I tried to put together a list, but it is not working. In the Preview only Item 1, Subitem 1
appears.
Follow the .Java
public class Lista extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_lista);
String[] alunos = {"Ygor", "Carlos", "Paulo", "Joao", "Pedro"}; //Defini o vetor com os nomes
ListView lista_alunos = (ListView) findViewById(R.id.lista); //(ListView) serve para converter a referência para ListView
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, alunos); //Transformar o Array para View
lista_alunos.setAdapter(adapter); //Aqui a lista vai pedir para o adapter realizar a conversão para View
}
}
and the .xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lista"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Could anyone see what's wrong with this code? I could not figure out where the error is.