Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 13 days ago
JSON representation

An Android library that provides a simple and customizable ValuePicker.

Awesome Lists containing this project

README

        

# ValuePicker
An Android library that provides a simple and customizable ValuePicker.

![](https://img.shields.io/badge/API-21%2B-orange.svg?style=flat)
[![Platform](https://img.shields.io/badge/platform-Android-green.svg)](http://developer.android.com/index.html)
[![Download](https://img.shields.io/maven-central/v/com.paulrybitskyi.valuepicker/valuepicker.svg?label=Download)](https://search.maven.org/search?q=com.paulrybitskyi.valuepicker)
[![Build](https://github.com/mars885/value-picker/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/mars885/value-picker/actions)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ValuePicker-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/8212)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](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).