I have an activity_main layout with a ListView.
I need to fill my ListView in MainActivity.
MainActivity doesn't extend ListActivity, because I use not only a ListView in my layout, I use other elements.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top_level);
ListView listView = (ListView) findViewById(R.id.mylist);
}
Item.items
returns an array which I need to add to the ListView.
How Can I do that?
I know that I have to use an ArrayAdapter. But I can't do it properly.
It works for me, but I don't understand using android.R.layout.simple_list_item_1
.
ArrayAdapter<Item> itemsAdapter =
new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Item.items);
listView.setAdapter(itemsAdapter);