Dipika
Dipika

Reputation: 1127

How to create a dialog with up down buttons same as Datepicker with my own list of data

i want to create a dialog same as Datepicker or Numberpicker , (with up down buttons) with my own list of data items. On the click of up or down button , want corresponding shifting of list'items same as Datepicker do. can anyone describe how can i do this with my own list of items. Thanks....

Upvotes: 0

Views: 95

Answers (1)

Thanos
Thanos

Reputation: 3665

You need to instantiate a new NumberPicker:

NumberPicker np=(NumberPicker) findViewById(R.id.numberPicker);

Of course, you need to instantiate it the the XML layout file and name it "numberPicker" (or whatever you like but remember to replace the name in here: R.id.numberPicker)

Then, create the array of Strings that will be the choices of your NumberPicker. For example:

String[] values=new String[3];
values[0]="mike";
values[1]="sue";
values[2]="harry";

Then set set the value array to it, the Max and Min values for the picker (this is what will be returned for each value. The code provided below works for any values array like the one above)

np.setMaxValue(values.length-1);
np.setMinValue(0);
np.setDisplayedValues(values);

All the code was taken from this guide where you can also find more information, examples and styling solutions.

Upvotes: 2

Related Questions