leonardarnold/NumberPickerPreference


Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.leonardarnold:NumberPickerPreference:'
	}
	dependencies {
		implementation("com.github.leonardarnold:NumberPickerPreference:")
	}
	<dependency>
	    <groupId>com.github.leonardarnold</groupId>
	    <artifactId>NumberPickerPreference</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.leonardarnold" % "NumberPickerPreference" % ""
        
        

                            
    :dependencies [[com.github.leonardarnold/NumberPickerPreference ""]]
        
        

Readme


NumberPickerPreference

This repository is about a number picker dialog in a PreferenceActivity. As you have e.g. EditTextPreference or CheckboxPreference i needed a simple dialog with a number picker which is configurable via xml and updates his summary automatically. You find the screenshots below. #Usage If you use a PreferenceFragment:

    public static class PrefsFragment extends PreferenceFragment {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Load the preferences from an XML resource
            addPreferencesFromResource(R.xml.preferences);
        }
    }

example of a preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <PreferenceCategory android:title="General">
        <de.leonardarnold.numberpickerpreference.NumberPickerPreference
            android:defaultValue="18"
            android:key="number_picker"
            app:MaxValue="15"
            app:MinValue="1"
            android:summary="number picked: %s"
            android:title="Give me a number" />
    </PreferenceCategory>
</PreferenceScreen>

The max. or min. value will be defined like:

app:MaxValue="15"
app:MinValue="1"

The %s in the summary will be replaced with the actual value of the picker.

android:summary="number picked: %s"

If the default value is out of the min-max range you get a warning via logcat.

NumberPickerPreference screenshot number picker preference preferences NumberPickerPreference screenshot number picker preference preferences