Junior — Middle
Can you explain what a ListView component is and how it is used in interface development?
sobes.tech AI
Answer from AI
ListView is a user interface component in Android designed for displaying a scrollable list of items.
Main features of ListView:
- Allows displaying a large number of items using optimization through view recycling.
- Uses an adapter (
Adapter) to bind data to interface elements. - Supports handling clicks on list items.
Example of using ListView:
ListView listView = findViewById(R.id.listView);
String[] items = {"Item 1", "Item 2", "Item 3"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);
In modern applications, RecyclerView is often used instead of ListView for greater flexibility and performance.