【问题标题】:Dialog to pick number and String选择数字和字符串的对话框
【发布时间】:2017-01-09 04:15:24
【问题描述】:

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

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

【问题讨论】:

标签: android dialog numbers picker


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 1970-01-01
      • 2014-04-06
      • 2013-07-22
      • 1970-01-01
      • 2013-07-12
      • 2014-01-12
      • 2011-10-23
      • 2021-05-18
      相关资源
      最近更新 更多