public class

PickerColumn

extends java.lang.Object

 java.lang.Object

↳androidx.leanback.widget.picker.PickerColumn

Gradle dependencies

compile group: 'androidx.leanback', name: 'leanback', version: '1.2.0-alpha04'

  • groupId: androidx.leanback
  • artifactId: leanback
  • version: 1.2.0-alpha04

Artifact androidx.leanback:leanback:1.2.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.leanback:leanback com.android.support:leanback-v17

Androidx class mapping:

androidx.leanback.widget.picker.PickerColumn android.support.v17.leanback.widget.picker.PickerColumn

Overview

Picker column class used by Picker, defines a contiguous value ranges and associated labels. A PickerColumn has a minValue and maxValue to choose between. The Picker column has a current value. The labels can be dynamically generated from value by PickerColumn.setLabelFormat(String) or a list of static labels set by PickerColumn.setStaticLabels(CharSequence[]).

Summary

Constructors
publicPickerColumn()

Methods
public intgetCount()

Get total items count between minValue and maxValue.

public intgetCurrentValue()

Returns current value of the Column.

public java.lang.CharSequencegetLabelFor(int value)

Get a label for value.

public java.lang.StringgetLabelFormat()

Return string format (see format) to display label for value.

public intgetMaxValue()

Returns maximum value of the Column.

public intgetMinValue()

Returns minimal value of the Column.

public java.lang.CharSequencegetStaticLabels()

Returns static labels for each value, minValue maps to labels[0], maxValue maps to labels[labels.length - 1].

public voidsetCurrentValue(int value)

Sets current value of the Column.

public voidsetLabelFormat(java.lang.String labelFormat)

Set string format (see format) to display label for an integer value.

public voidsetMaxValue(int maxValue)

Sets maximum value of the Column.

public voidsetMinValue(int minValue)

Sets minimal value of the Column.

public voidsetStaticLabels(java.lang.CharSequence labels[])

Set static labels for each value, minValue maps to labels[0], maxValue maps to labels[labels.length - 1].

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PickerColumn()

Methods

public void setLabelFormat(java.lang.String labelFormat)

Set string format (see format) to display label for an integer value. PickerColumn.setStaticLabels(CharSequence[]) overrides the format.

Parameters:

labelFormat: String format to display label for value between minValue and maxValue.

public java.lang.String getLabelFormat()

Return string format (see format) to display label for value.

Returns:

String format to display label for value.

public void setStaticLabels(java.lang.CharSequence labels[])

Set static labels for each value, minValue maps to labels[0], maxValue maps to labels[labels.length - 1].

Parameters:

labels: Static labels for each value between minValue and maxValue.

public java.lang.CharSequence getStaticLabels()

Returns static labels for each value, minValue maps to labels[0], maxValue maps to labels[labels.length - 1]. When null, PickerColumn.getLabelFormat() will be used.

public java.lang.CharSequence getLabelFor(int value)

Get a label for value. The label can be static PickerColumn.setStaticLabels(CharSequence[]) or dynamically generated PickerColumn.setLabelFormat(String) when static labels is null.

Parameters:

value: Value between minValue and maxValue.

Returns:

Label for the value.

public int getCurrentValue()

Returns current value of the Column.

Returns:

Current value of the Column.

public void setCurrentValue(int value)

Sets current value of the Column.

public int getCount()

Get total items count between minValue and maxValue.

Returns:

Total items count between minValue and maxValue.

public int getMinValue()

Returns minimal value of the Column.

Returns:

Minimal value of the Column.

public int getMaxValue()

Returns maximum value of the Column.

Returns:

Maximum value of the Column.

public void setMinValue(int minValue)

Sets minimal value of the Column.

Parameters:

minValue: New minimal value to set.

public void setMaxValue(int maxValue)

Sets maximum value of the Column.

Parameters:

maxValue: New maximum value to set.

Source

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package androidx.leanback.widget.picker;

/**
 * Picker column class used by {@link Picker}, defines a contiguous value ranges and associated
 * labels.  A PickerColumn has a minValue and maxValue to choose between.  The Picker column has
 * a current value.
 * The labels can be dynamically generated from value by {@link #setLabelFormat(String)} or
 * a list of static labels set by {@link #setStaticLabels(CharSequence[])}.
 */
public class PickerColumn {

    private int mCurrentValue;
    private int mMinValue;
    private int mMaxValue;
    private CharSequence[] mStaticLabels;
    private String mLabelFormat;

    public PickerColumn() {
    }

    /**
     * Set string format (see {@link String#format}) to display label for an
     * integer value.  {@link #setStaticLabels(CharSequence[])} overrides the format.
     *
     * @param labelFormat String format to display label for value between minValue and maxValue.
     */
    public void setLabelFormat(String labelFormat) {
        mLabelFormat = labelFormat;
    }

    /**
     * Return string format (see {@link String#format}) to display label for
     * value.
     * @return String format to display label for value.
     */
    public String getLabelFormat() {
        return mLabelFormat;
    }

    /**
     * Set static labels for each value, minValue maps to labels[0], maxValue maps to
     * labels[labels.length - 1].
     * @param labels Static labels for each value between minValue and maxValue.
     */
    public void setStaticLabels(CharSequence[] labels) {
        mStaticLabels = labels;
    }

    /**
     * Returns static labels for each value, minValue maps to labels[0], maxValue maps to
     * labels[labels.length - 1].  When null, {@link #getLabelFormat()} will be used.
     */
    public CharSequence[] getStaticLabels() {
        return mStaticLabels;
    }

    /**
     * Get a label for value. The label can be static {@link #setStaticLabels(CharSequence[])}
     * or dynamically generated {@link #setLabelFormat(String)} when static labels is null.
     *
     * @param value Value between minValue and maxValue.
     * @return Label for the value.
     */
    public CharSequence getLabelFor(int value) {
        if (mStaticLabels == null) {
            return String.format(mLabelFormat, value);
        }
        return mStaticLabels[value];
    }

    /**
     * Returns current value of the Column.
     * @return Current value of the Column.
     */
    public int getCurrentValue() {
        return mCurrentValue;
    }

    /**
     * Sets current value of the Column.
     */
    public void setCurrentValue(int value) {
        mCurrentValue = value;
    }

    /**
     * Get total items count between minValue and maxValue.
     * @return Total items count between minValue and maxValue.
     */
    public int getCount() {
        return mMaxValue - mMinValue + 1;
    }

    /**
     * Returns minimal value of the Column.
     * @return Minimal value of the Column.
     */
    public int getMinValue() {
        return mMinValue;
    }

    /**
     * Returns maximum value of the Column.
     * @return Maximum value of the Column.
     */
    public int getMaxValue() {
        return mMaxValue;
    }

    /**
     * Sets minimal value of the Column.
     * @param minValue New minimal value to set.
     */
    public void setMinValue(int minValue) {
        mMinValue = minValue;
    }

    /**
     * Sets maximum value of the Column.
     * @param maxValue New maximum value to set.
     */
    public void setMaxValue(int maxValue) {
        mMaxValue = maxValue;
    }

}