选择数字和字符串的对话框

Dialog to pick number and String

我需要一个允许我从三个中选择一个数字和一个字符串的对话框。 用户应选择一个字符串(年、月、周),然后选择 y、m 或 w 的数字。

任何人都知道如何让它看起来像这样

试试这些库:NumberPicker,VNTNumberPickerPreference

所以是的,我只是在这里使用了这段代码并更改了一些我需要的东西,这就成功了

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();
}