答案 0 :(得分:2)
所以是的,我只是在这里使用了这段代码并改变了我需要的一些东西,这就是诀窍
public void AgeDialog(){
final android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(this);
alert.setCancelable(false);
LinearLayout l1 = new LinearLayout(getApplicationContext());
l1.setOrientation(LinearLayout.HORIZONTAL);
final NumberPicker number =new NumberPicker((this));
number.setMaxValue(12);
number.setMinValue(1);
number.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
number.setWrapSelectorWheel(true);
final NumberPicker ageUnitss = new NumberPicker(this);
final String arrays[] = new String[3];
arrays[0]="Years";
arrays[1]="Months";
arrays[2]="Days";
ageUnitss.setMaxValue(2);
ageUnitss.setMinValue(0);
ageUnitss.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
ageUnitss.setDisplayedValues(arrays);
ageUnitss.setWrapSelectorWheel(true);
l1.addView(number);
l1.addView(ageUnitss);
l1.setHorizontalGravity(Gravity.CENTER_HORIZONTAL);
alert.setView(l1);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ageUnits = arrays[(ageUnitss.getValue())];
age = number.getValue();
fragment1.setAgeText(age +" "+ageUnits);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
}
答案 1 :(得分:0)