Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -41,8 +42,8 @@ public class NumberPicker extends LinearLayout {

// ui components
private Context mContext;
private Button decrementButton;
private Button incrementButton;
private View decrementButton;
private View incrementButton;
private EditText displayEditText;

// listeners
Expand Down Expand Up @@ -85,8 +86,8 @@ private void initialize(Context context, AttributeSet attrs) {
LayoutInflater.from(this.mContext).inflate(layout, this, true);

// init ui components
this.decrementButton = (Button) findViewById(R.id.decrement);
this.incrementButton = (Button) findViewById(R.id.increment);
this.decrementButton = findViewById(R.id.decrement);
this.incrementButton = findViewById(R.id.increment);
this.displayEditText = (EditText) findViewById(R.id.display);

// register button click and action listeners
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/drawable/ic_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
5 changes: 5 additions & 0 deletions sample/src/main/res/drawable/ic_remove.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can rename this file as ic_subtract instead? Because the button's purpose is to subtracting, not removing the number.

Or maybe it's better if the name follows the views ids as below:

  • ic_add.xml -> ic_increment.xml
  • ic_remove.xml -> ic_decrement.xml

android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13H5v-2h14v2z"/>
</vector>
24 changes: 17 additions & 7 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:numberpicker="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
xmlns:numberpicker="http://schemas.android.com/apk/res-auto"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.travijuu.numberpicker.sample.MainActivity">

<com.travijuu.numberpicker.library.NumberPicker
android:id="@+id/number_picker_default"
android:layout_width="130dp"
android:layout_height="40dp"/>
android:layout_height="40dp" />

<com.travijuu.numberpicker.library.NumberPicker
android:id="@+id/number_picker_custom"
android:layout_width="130dp"
android:layout_height="40dp"
numberpicker:custom_layout="@layout/number_picker_custom_layout"
numberpicker:max="10"
numberpicker:min="0"
numberpicker:unit="1"
numberpicker:value="-5" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it create an error? Because the min value is 0 but you set a negative number (below 0) as the value.


<com.travijuu.numberpicker.library.NumberPicker
android:id="@+id/number_picker_custom_image_buttons"
android:layout_width="130dp"
android:layout_height="40dp"
numberpicker:custom_layout="@layout/number_picker_custom_layout_image_buttons"
numberpicker:max="10"
numberpicker:value="-5"
numberpicker:min="0"
numberpicker:unit="1"
numberpicker:custom_layout="@layout/number_picker_custom_layout" />
numberpicker:value="-5" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="130dp"
android:layout_height="40dp"
android:orientation="horizontal">

<ImageButton
android:id="@+id/decrement"
android:layout_width="30dp"
android:layout_height="match_parent"
android:backgroundTint="@color/colorPrimary"
android:padding="0dp"
android:src="@drawable/ic_remove"
android:text="@string/decrement"
android:textStyle="bold" />

<EditText
android:id="@+id/display"
android:layout_width="70dp"
android:layout_height="match_parent"
android:gravity="center"
android:inputType="number"
android:text="@string/display"
android:textColor="@android:color/black" />

<ImageButton
android:id="@+id/increment"
android:layout_width="30dp"
android:layout_height="match_parent"
android:backgroundTint="@color/colorPrimary"
android:padding="0dp"
android:src="@drawable/ic_add"
android:text="@string/increment"
android:textSize="25sp" />

</LinearLayout>