SGiOSViews
Shubhank101
13
Visit GitHub RepoOther Pickers

Common iOS Views ported to Android

Requirements

Android Studio (gradle) Min sdk 15

Demo

Demo

Usage

Add this to your build.gradle dependencies

compile 'com.github.shubhank101.sgiosviews:sgiosviews-lib:1.0.0'

SGStepper

A port of iOS UIStepper, can be used a simple number picker

Usage

Add the following code to the root element of layout

xmlns:stepper="http://schemas.android.com/apk/res-auto"

Adding the element to the xml

<com.sgiosviews.SGStepper    
    android:id="@+id/stepper"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    stepper:roundedradius="0dp"
    stepper:bordercolor="#fff"
    stepper:highlightcolor="#ccc"
/>

Getting Values in Java

SGStepper stepper = (SGStepper)findViewById(R.id.stepper);
stepper.setValueChangedlistener(new SGStepper.SGStepperListener() {

    @Override
    public void valuesChanged(SGStepper stepper, int newValue) {
    }

    @Override
    public void afterValueChanged(SGStepper stepper, int finalValue) {
    }
});

SGPickerView

A very basic port of iOS UIPickerView.

Usage

Add the following code to the root element of layout

xmlns:picker="http://schemas.android.com/apk/res-auto"

Adding the element to the xml

<com.sgiosviews.SGPickerView
    android:id="@+id/pickerView"
    android:layout_width="match_parent"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginBottom="40dp"
    android:layout_height="wrap_content"
    picker:defaultTextColor="#ccc"
    picker:selectedTextColor="#666"/>

Setting Picker Values in Java

pickerView = (SGPickerView)findViewById(R.id.pickerView);

ArrayList<String> items = new ArrayList<String>();
items.add("Funny");
items.add("Awesomeeeee");
pickerView.setItems(items);

Listening to any new selection of element

pickerView.setPickerListener(new SGPickerView.SGPickerViewListener() {
    @Override
    public void itemSelected(String item, int index) {
        Toast.makeText(MainActivity.this, " Index = " + String.valueOf(index) + " Item name " + item, Toast.LENGTH_SHORT).show();
    }
});

Public methods to access selected index or item at any time

pickerView.getCurrentSelectedItemIndex();
pickerView.getCurrentSelectedItem();

Developed By

Shubhank Gupta, shubhankscores@gmail.com

License

Copyright (c) 2016 Shubhank Gupta, Licensed under the MIT license.

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT