Ich habe ein Problem über Listview mit String-Element gefüllt, obwohl ich eine Suche darüber nachschlagen. Ich verstehe nicht, wo die Probleme herkommen, obwohl ich layout.xml korrekt definiere. Wie kann ich es lösen?Android Listview leider App hat gestoppt
public class A extends AppCompatActivity {
ArrayList<String> items= null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a);
items = new ArrayList<String>();
items.add("AAAA");
items.add("BBB");
items.add("CCC");
items.add("DDD");
ArrayAdapter<String> itemsAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
ListView listView = (ListView) findViewById(R.id.listviewAttactivePlaces);
listView.setAdapter(itemsAdapter);
}
a.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listviewAttactivePlaces"
tools:context="com.example.android.turkeytourguide.AttactivePlacesActivity">
</ListView>
Sie müssen das Objekt der ArrayList erstellen items = new ArrayList (); Innerhalb der OnCreate-Methode –