https://github.com/mars885/value-picker
An Android library that provides a simple and customizable ValuePicker.
https://github.com/mars885/value-picker
android android-library android-pickers android-pickerview
Last synced: 3 months ago
JSON representation
An Android library that provides a simple and customizable ValuePicker.
- Host: GitHub
- URL: https://github.com/mars885/value-picker
- Owner: mars885
- License: apache-2.0
- Created: 2020-08-15T13:01:59.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-20T19:37:58.000Z (5 months ago)
- Last Synced: 2025-04-10T00:06:21.051Z (3 months ago)
- Topics: android, android-library, android-pickers, android-pickerview
- Language: Kotlin
- Homepage:
- Size: 582 KB
- Stars: 53
- Watchers: 1
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ValuePicker
An Android library that provides a simple and customizable ValuePicker.
[](http://developer.android.com/index.html)
[](https://search.maven.org/search?q=com.paulrybitskyi.valuepicker)
[](https://github.com/mars885/value-picker/actions)
[](https://android-arsenal.com/details/1/8212)
[](https://opensource.org/licenses/Apache-2.0)## Contents
* [Demo](#demo-youtube)
* [Installation](#installation)
* [Usage](#usage)
* [Advanced Usage](#advanced-usage)
* [License](#license)## Demo (YouTube)
## Installation
1. Make sure that you've added the `mavenCentral()` repository to your top-level `build.gradle` file.
````groovy
buildscript {
//...
repositories {
//...
mavenCentral()
}
//...
}
````2. Add the library dependency to your module-level `build.gradle` file.
````groovy
dependencies {
//...
implementation "com.paulrybitskyi.valuepicker:valuepicker:1.0.3"
//...
}
````## Usage
Basic usage of the ValuePickerView involves two steps - declaring a widget inside the XML file of your choice and configuring it in one of the Kotlin/Java classes.Let's see how we can do that by following the steps listed above:
1. Declaring a widget inside the XML file.
XML (click to expand)
````xml
````
2. Configuring the widget in one of the Kotlin/Java classes.
Kotlin (click to expand)
````kotlin
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)//...
with(valuePickerView) {
onItemSelectedListener = ValuePickerView.OnItemSelectedListener { item ->
// Do something with item
}val pickerItems = getPickerItems()
items = pickerItems
setSelectedItem(pickerItems[2])
}
}private fun getPickerItems(): List {
return buildList {
for(number in 1..100) {
add(
PickerItem(
id = number,
title = number.toString()
)
)
}
}
}
````
Java (click to expand)
````java
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);ValuePickerView valuePickerView = view.findViewById(R.id.valuePickerView);
valuePickerView.setOnItemSelectedListener((item) -> {
// Do something with item
});final ArrayList pickerItems = getPickerItems();
valuePickerView.setItems(getPickerItems());
valuePickerView.setSelectedItem(pickerItems.get(2));
}private ArrayList getPickerItems() {
final ArrayList pickerItems = new ArrayList<>(100);for(int i = 1; i <= 100; i++) {
pickerItems.add(
new PickerItem(
i,
String.valueOf(i)
)
);
}return pickerItems;
}
````
## Advanced Usage
See the [Sample app](https://github.com/mars885/value-picker/tree/master/sample/src/main/java/com/paulrybitskyi/valuepicker/sample).
## License
ValuePicker is licensed under the [Apache 2.0 License](LICENSE).