Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add fast scroll to a AlertDialog.Builder scrolllist

I have a large list of users being displayed in an AlertDialog as a selection list. This is the code I am using to generate it:

 AlertDialog.Builder builder = new AlertDialog.Builder(thisContext);
                    builder.setTitle("User");
                    builder.setItems(userNames, new  DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int pos) {
                        //selection processing code

                }});
                builder.setNeutralButton("Clear", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //clear processing code
                    }});
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });
                dialog=builder.create();
                //next line added as solution
                dialog.getListView().setFastScrollEnabled(true); 
                dialog.show();

userNames is an alphebetical list of names from the database.

This works very well for the most part, however, because I have over 100 or more users, scrolling through the list is a little slow. How can I go about adding fast scroll so that the users may be able to jump to a part further down in the list when needed?

like image 493
cain Avatar asked Dec 27 '22 00:12

cain


1 Answers

Have you tried calling getListView().setFastScrollEnabled(true) on the AlertDialog?

like image 146
MH. Avatar answered Jan 12 '23 04:01

MH.