0
I’m starting now with the development for Android. I tried to put together a list but it’s not working. Preview only appears Item 1, Subitem 1
.
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 . 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 couldn’t figure out where the bug is.
What’s your question? This should work yes showing all items in list format. From what I see there is no subitem.
– viana
In my Androidstudio "Preview", only "Item 1, Sub Item1, Item2, Sub Item2" appears, my question is why the String is not appearing?
– Ygor Fraga
The preview will never show up anyway. You need to compile your project to make it work.
– viana
Before were appearing the names when I put all the names in "Textview", I will test here.
– Ygor Fraga
In text view it does appear, but everything you put inside your class will only appear if you compile.
– viana
I went on Android simulator and is appearing "process system isn’t responding". You know what can be?
– Ygor Fraga
I don’t know. You could edit your question and instead of putting "simulator" put what is in "Preview" your test.
– viana