4

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?

cain
  • 1,028
  • 1
  • 12
  • 26
  • 2
    Have you tried calling [`getListView()`](http://developer.android.com/reference/android/app/AlertDialog.html#getListView%28%29)`.`[`setFastScrollEnabled(true)`](http://developer.android.com/reference/android/widget/AbsListView.html#setFastScrollEnabled%28boolean%29) on the `AlertDialog`? – MH. May 21 '12 at 20:44
  • MH. That worked beautifully. Add it as an answer and I'll approve it. – cain May 21 '12 at 20:52
  • Cool, glad to be of help. Happy coding. :) – MH. May 21 '12 at 21:43

1 Answers1

10

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

MH.
  • 45,303
  • 10
  • 103
  • 116