how to scroll listview to specific position in android programmatically
Try this:
listview_nearby_locations.setSelection(9);
Programmatically set position in ListView without scrolling
There is a method in AbsListView, called smoothScrollToPositionFromTop()
and it takes duration
parameter. So if you set it to 0, you may do it without scrolling, animation.
smoothScrollToPositionFromTop.
How to scroll to an item at specific position (that is not in view), in recycler view in android?
Use below code:
yourRecyclerViewObject.getLayoutManager().scrollToPosition(itemPosition);
How to scroll to a specific list position inside AlertDialog
You can use AlertDialog
to get the list and after show you can scroll to a certain position.
Try this way it should work .
fun createAlert(activity: Activity, mandatory: Boolean, provinceSelected: (Int) -> Unit) {
val provinceDialog: AlertDialog.Builder = AlertDialog.Builder(activity)
provinceDialog.setTitle(activity.getString(R.string.select_province_from_list))
provinceDialog.setCancelable(!mandatory)
val arrayAdapter = ArrayAdapter<String>(activity, R.layout.province_list_row_item, SubAdministrativeAreas.provincesList)
provinceDialog.setAdapter(arrayAdapter
) { _, positionSelected ->
provinceSelected(positionSelected)
}
val dialog = provinceDialog.create()
dialog.setOnShowListener {
dialog.listView.smoothScrollToPosition(11)
}
dialog.show()
}
How can I set the initial scroll position of my list?
calling
listview.post(new Runnable() {
@Override
public void run() {
listview.setSelection(mSelectedPosition);
}
});
seems to have helped others.
Related Topics
Intercept Back Button from Soft Keyboard
Android Camera Preview Stretched
Error Android Emulator Gets Killed in Android Studio
How to Hide Action Bar Before Activity Is Created, and Then Show It Again
How to Pass the Values from One Activity to Previous Activity
How to Write Files to Assets Folder or Raw Folder in Android
Android Emulator Doesn't Take Keyboard Input - Sdk Tools Rev 20
Make Certain Area of Bitmap Transparent on Touch
Difference Between .Getpath() VS Cursor in Getting the Real Path of a File from Uri in Android
Get Clicked Item and Its Position in Recyclerview
Bitmapfactory Oom Driving Me Nuts
Android: Allow Portrait and Landscape for Tablets, But Force Portrait on Phone
Error:(6, 0) Gradle Dsl Method Not Found: 'Google()'
Calling Startactivity() from Outside of an Activity Context
How to Implement Multi-Select in Recyclerview
How to Detect User Pressing Home Key in My Activity