This android Number Picker dialogs that will allow a user to pick a number within a certain range? It seems like this would be a fairly common need, Here is a sample Solution to create android Number Picker Dialog.
Here is same code to create Android Number Picker:::
package com.gafur.numberPicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class NumberPickerActivity extends Activity {
private Button upButton;
private Button downButton;
private EditText editText;
private int uprange = 20;
private int downrange = 0;
private int values = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
upButton = (Button) findViewById(R.id.upButton);
downButton = (Button) findViewById(R.id.downButton);
editText = (EditText) findViewById(R.id.numberEditText);
upButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
downButton.setBackgroundResource(R.drawable.timepicker_down_normal);
upButton.setBackgroundResource(R.drawable.timepicker_up_pressed);
if (values >= downrange && values <= uprange)
values++;
if (values > uprange)
values = downrange;
editText.setText(“” + values);
}
});
downButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
downButton .setBackgroundResource(R.drawable.timepicker_down_pressed);
upButton.setBackgroundResource(R.drawable.timepicker_up_normal);
if (values >= downrange && values <= uprange)
values–;
if (values < downrange)
values = uprange;
editText.setText(values + “”);
}
});
}
}
Here main XML Layout:::
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”center”
android:orientation=”vertical”
android:padding=”10dp” >
<Button
android:id=”@+id/upButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/timepicker_up_normal” />
<EditText
android:id=”@+id/numberEditText”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/timepicker_input_selected”
android:gravity=”center”
android:inputType=”number” >
<requestFocus />
</EditText>
<Button
android:id=”@+id/downButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/timepicker_down_normal” />
</LinearLayout>
Some Picture that are need to make same UI:::