All Projects → mars885 → value-picker

mars885 / value-picker

Licence: Apache-2.0 license
An Android library that provides a simple and customizable ValuePicker.

Programming Languages

kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to value-picker

HmsPickerView
A beautiful little Android view to pick hours, minutes and seconds.
Stars: ✭ 18 (-61.7%)
Mutual labels:  android-pickers, android-pickerview
QuantityPickerView
A View capable of increasing or decreasing a unit value with a toggle animation
Stars: ✭ 42 (-10.64%)
Mutual labels:  android-pickers, android-pickerview
recurpickerlib
Recurrence picker fragment and dialog for Android, with utilities for finding recurrence dates
Stars: ✭ 64 (+36.17%)
Mutual labels:  android-pickers
Android Pickerview
This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
Stars: ✭ 13,003 (+27565.96%)
Mutual labels:  android-pickerview

ValuePicker

An Android library that provides a simple and customizable ValuePicker.

Platform Download Build Android Arsenal License

Contents

Demo (YouTube)

Installation

  1. Make sure that you've added the mavenCentral() repository to your top-level build.gradle file.
buildscript {
    //...
    repositories {
        //...
        mavenCentral()
    }
    //...
}
  1. Add the library dependency to your module-level build.gradle file.
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 version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary">
    
        <!-- Other widgets here -->
    
        <com.paulrybitskyi.valuepicker.ValuePickerView
            android:id="@+id/valuePickerView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:vpv_areDividersEnabled="true"
            app:vpv_isInfiniteScrollEnabled="true"
            app:vpv_maxVisibleItems="5"
            app:vpv_textColor="@color/colorAccent"
            app:vpv_dividerColor="@color/colorAccent"
            app:vpv_flingSpeedFactor="0.3"
            app:vpv_textSize="@dimen/date_picker_text_size"
            app:vpv_textTypeface="@font/ubuntu_mono_bold"
            app:vpv_divider="@drawable/custom_divider"
            app:vpv_orientation="vertical"/>
    
    </androidx.constraintlayout.widget.ConstraintLayout>

  2. Configuring the widget in one of the Kotlin/Java classes.

    Kotlin (click to expand)

    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<Item> {
        return mutableListOf<Item>().apply {
            for(number in 1..100) {
                add(
                    PickerItem(
                        id = number,
                        title = number.toString()
                    )
                )
            }
        }
    }

    Java (click to expand)

    @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<Item> pickerItems = getPickerItems();
    
        valuePickerView.setItems(getPickerItems());
        valuePickerView.setSelectedItem(pickerItems.get(2));
    }
    
    
    private ArrayList<Item> getPickerItems() {
        final ArrayList<Item> 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.

License

ValuePicker is licensed under the Apache 2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].