I' have a problem about 'rendering' with my NumberPicker inside an AlertDialog.
I show to you the code:
//setup del dialog
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setCancelable(false);
final NumberPicker picker = new NumberPicker(activity);
picker.setMinValue(0);
picker.setMaxValue(5);
//set bottoni dialog
builder.setPositiveButton(R.string.dialog_btn_seleziona, seleziona);
builder.setNegativeButton(R.string.dialog_btn_annulla, null);
//visualizzo il dialog
Dialog dialog = builder.create();
dialog.show();
the problem is that instead of to have a result like this:
I have this result:
The blue line selector is too long, i would like the same lenght of the first picture
i founded this topic:
NumberPicker rendered incorrectly in a Dialog
that explain how to fix this problem, and the solution is:
instead of this
android:layout_width="match_parent"
You should use
android:layout_width="wrap_content"
android:layout_gravity="center"
the problem is that i dont have a layout (made by myself for this numberpicker) so i need to set this parameters programmatically, but i don't know how.
Sorry, I misunderstood earlier. You just need to create a parent view and put your picker inside of that, using wrap_content. Here is how you do that in code:
final NumberPicker picker = new NumberPicker(activity);
picker.setMinValue(0);
picker.setMaxValue(5);
final FrameLayout parent = new FrameLayout(activity);
parent.addView(picker, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER));
builder.setView(parent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With