Android Application Development (AND-401) — Question 36
Which of the following is true about object arrayAdapter declared in the code below?
String[] items = {"Item 1","Item 2","Item 3"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items); listView.setAdapter(arrayAdapter);
Answer options
- A. It creates a TextView for each String in array items.
- B. It creates Buttons for each String in array items.
- C. It creates four views for listView.
- D. It replaces the layout of the activity with three consecutive TextView items.
Correct answer: A
Explanation
The correct answer is A because the ArrayAdapter is designed to create a TextView for each item in the provided String array. Options B and D are incorrect as the ArrayAdapter does not create Buttons or replace the layout of the activity. Option C is also wrong since it only creates three views corresponding to the three items in the array.