// Get the ListView ListView listView = findViewById(R.id.my_list_view); // Scroll to the 5th item from the top with a 50 pixel offset listView.setSelectionFromTop(4, 50);
// Create a new ArrayAdapter ArrayAdapterThis example sets up a ListView with an ArrayAdapter and then scrolls to the last item in the ListView using setSelectionFromTop. The library used in these examples is the Android SDK package, specifically the android.widget package.adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, myStringArray); // Set the adapter for the ListView ListView listView = findViewById(R.id.my_list_view); listView.setAdapter(adapter); // Scroll to the last item in the ListView int lastItemPosition = adapter.getCount() - 1; listView.setSelectionFromTop(lastItemPosition, 0);