ListView listView = findViewById(R.id.list_view); // Add items to the list String[] items = {"Item 1", "Item 2", "Item 3"}; ArrayAdapteradapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items); listView.setAdapter(adapter); // Get the number of items in the list int itemCount = listView.getChildCount(); Log.d(TAG, "Number of items: " + itemCount);
// Set the background color of every other item in the list for (int i = 0; i < listView.getChildCount(); i++) { if (i % 2 == 0) { listView.getChildAt(i).setBackgroundColor(Color.GRAY); } else { listView.getChildAt(i).setBackgroundColor(Color.WHITE); } }The android.widget.ListView class is part of the Android framework and does not require any external libraries or packages.