Increase Number Picker Wheel Item Count - Default set to 3 items in the Wheel

Hello guys! I am new to Kotlin and I cannot figure out to display more then 3 elements in a wheel. For example if the array is 1 to 10 the wheel will display (wheel is wraped)
10
1
2

I am trying to have the wheel to display 5 elements (should look something like this)
9
10
1
2
3

I look through stackoverflow and find out there is this code that is set to 3
SELECTOR_WHEEL_ITEM_COUNT = 3
This code is not in Kotlin and thus does not work :frowning:
This has been very difficult and not sure if I am missing something.

Thanks!

What platform are you developing for? I guess it is android, but it would be good to know.
Also can you show some code snipet? How do you create the wheel? Where do you set the data? Also please only post parts of your code and not everything.

As for the SO answer. I don’t know what you found exactly, but it looks like they are defining a constant for the number of items to display. If you go back to the SO post, try to look at where else they use that constant. That should tell you how to set the number of items displayed.

Sorry, its in android studio. The post I was talking about was this one but it’s for Java (I could not find much info on number picker for Koltin)

I assume the code SELECTOR_WHEEL_ITEM_COUNT does not work in Kotlin and could not find similar code

I am creating a memorization app and using the wheel to select the chapter and verses. There is a total of 3 wheels. Here are the arrays, The arrays are in values > array_lists.xml

<string-array name = 'chapterArray'>
    <item>-</item>
    <item>Chapter 1</item>
    <item>Chapter 2</item>
    <item>Chapter 3</item> </string-array>

<string-array name = 'chapter1VerseArray'>
    <item>-</item>
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
    <item>6</item>
    <item>7</item> </string-array>

Here is part of the code of the wheel. This part sets the chapter wheel, fromWheel and toWheel before chatperWheel.setOnValueChangedListener

    //Initialize chapterWheelArray, fromWheelArray and toWheelArray as Array String
    var chapterWheelArray : Array<String>
    var fromWheelArray : Array<String>
    var toWheelArray : Array<String>

    chapterWheelArray = resources.getStringArray(R.array.chapterArray)

    chapterWheel.minValue = 0 ; surahWheel.maxValue = 3
    fromWheel.minValue = 0 ; fromWheel.maxValue = 0
    toWheel.minValue = 0 ; toWheel.maxValue = 0

    fromWheelArray = resources.getStringArray(R.array.chapterBlankArray)
    toWheelArray = resources.getStringArray(R.array.chapterBlankArray)

    fromWheel.displayedValues = fromWheelArray
    toWheel.displayedValues = toWheelArray

    chapterWheel.displayedValues = chapterWheelArray

    selectedStartingVerseToWheel = 0
    selectedStartingVerseFromWheel = 0

  
 chatperWheel.setOnValueChangedListener { _, oldVal, chapter ->

        //Prevents App from crashing when changing chapters
        fromWheel.displayedValues = null ; toWheel.displayedValues = null

        //Resets the Wheel to the first position of the array
        fromWheel.value = 0 ; toWheel.value = 0

        if (chapter == 1)
        {
            //Sets fromWheel and toWheel the min and max value of the array
            fromWheel.minValue = 0 ; toWheel.minValue = 0
            fromWheel.maxValue = 7 ; toWheel.maxValue = 7

            //Assign arrays to fromWheelArray and toWheelArray
            fromWheelArray = resources.getStringArray(R.array.chapter1VerseArray)
            toWheelArray = resources.getStringArray(R.array.chapter1VerseArray)

            //Displays the array for fromWheel and toWheel
            fromWheel.displayedValues = fromWheelArray
            toWheel.displayedValues = toWheelArray

            fromWheel.setOnValueChangedListener { _, oldVal, selectedStartingVerseFromWheel ->
                //Assigns a value to firstVerse depending on fromWheel selection
                firstVerse = selectedStartingVerseFromWheel

                toWheel.setOnValueChangedListener { _, oldVal, selectedStartingVerseToWheel ->
                    //Assigns a value to lastVerse depending on toWheel selection
                    lastVerse = selectedStartingVerseToWheel
                }
            }
        }

The chapter wheels will display as

Chapter 3
“-”
Chatper 1

the fromWheel will display as

7
“-”
1

I would like it to display more items in the wheel

Thanks!

I’m guessing you are using a NumberPicker(NumberPicker  |  Android Developers).
Based on the documentation I don’t think it is possible to change the number of elements displayed, at least not with this widget.

Also while looking for the number picker I found this which might help you.

Thank you! and sorry but I need a little bit of help! This is the first time I import anything to my build. I have done what the package tab said and sync’d android studio but it still does not recognize the chapterWheel.setWheelItemCount(5)

This is my build.gradle (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.70'
    repositories {
        google()
        jcenter()
        
  }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

   classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.5'

   // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
 }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url "https://jitpack.io" }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

This is my build.gradle (Module:app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.example.chapterwheeltest"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.github.SuperRabbitD:NumberPicker:d6c3a75e61'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

I have also copied the repositories and dependencies from the project you sent me and sync’d and still would not work. :frowning:

Thanks!