Android Float Picker Widget

Float Picker Widget is an open source Android based widget for picking a number using plus and minus buttons, no typing required. Widget supports whole numbers, decimals, positive values, and negative values. Configuration options include increment size, number of decimal places, minimum value, maximum value, etc. When user holds down button, the widget will continue incrementing the value and accelerate.

Could be used for picking specific scientific values (pH, temperature), AM/FM radio stations, quantity of items to purchase in lots.

 

Usage:

1) Setup Layout:

<com.laurencegellert.androidwidgets.FloatPickerWidget
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_alignParentTop="true"
	android:gravity="left"
	minimum_value="88.9f"
	maximum_value="105.9f"
	default_value="99.1f"
	increment_amount="0.1f"
	decimal_places="1"
	android:id="@+id/FloatPicker2" />

2) Add listener to activity:

public class DemoActivity extends Activity {

  private float p1_value;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

        FloatPickerWidget fpw1 = (FloatPickerWidget) findViewById(R.id.FloatPicker1);
        ChangeListener listener1 = new ChangeListener();
        fpw1.onValueChange(listener1);
  }

  private class ChangeListener implements FloatPickerWidget.ChangeListener {

	@Override
	public void onValueChange(FloatPickerWidget fpw, float value) {
		// in your app, do something interesting with the value when this fires
		p1_value = value;
		Log.i("Demo App", "Value of the first picker was changed to: " + value);
		return;
	}

  }
}

 

Configuration options, specified in the XML layout as attributes:

  • button_width – int – width of add and subtract buttons, defaults to 40.
  • button_height – int – height of add and subtract buttons, defaults to LayoutParams.FILL_PARENT.
  • button_text_size – int – size of text labels for buttons, defaults to 20.
  • edittext_width – int – text field width field, defaults to 80.
  • edittext_height – int – text field height, defaults to LayoutParams.FILL_PARENT.
  • edittext_size – int – size of text to use, integer, defaults to 20.
  • add_button_label – String – content of add button, defaults to ‘+’.
  • subtract_button_label – String – content of subtract button, defaults to ‘-‘.
  • minimum_value – float – minimum value allowed, defaults to 0f.
  • maximum_value – float – maximum value allowed, defaults to 100f.
  • default_value – float – default value, defaults to minimum_value.
  • increment_amount – float – amount to add/subtract when button pressed, defaults to 1f.
  • decimal_places – int – number of decimals to display, defaults to 0.
  • starting_repeat_rate – int – initial milliseconds between repeats, defaults to 200, must be above repeat_acceleration.
  • repeat_acceleration – int – milliseconds to decrement the repeat interval on
    each repeat, defaults to 50, do not set below 25.

License:

Apache 2.0
http://www.apache.org/licenses/LICENSE-2.0.html

Available on BitBucket:

https://bitbucket.org/laurencegellert/floatpickerwidget

I look forward to feedback, suggestions, thumbs up, thumbs down, bring it!

Comments are closed.