[java]
package de.clarisweb.android.listview;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView myListView = findViewById((R.id.myListView));
final ArrayList myFamily = new ArrayList();
myFamily.add("P1");
myFamily.add("P2");
myFamily.add("P3");
myFamily.add("P4");
myFamily.add("P5");
final ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, myFamily);
myListView.setAdapter(arrayAdapter);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int i, long l) {
Log.i("Person selected: ", myFamily.get(i));
Toast.makeText(MainActivity.this, "Person: " + myFamily.get(i) + " entfernt", Toast.LENGTH_SHORT).show();
arrayAdapter.remove(myFamily.get(i));
arrayAdapter.notifyDataSetChanged(); }
});
}
}
[/java]