1

我有一个按钮,单击该按钮必须生成一个包含数字选择器和确定取消按钮的对话框。我正在使用 Android 2.3.3(不是 API 11),所以我从这里下载了数字选择器。它工作正常。单击确定按钮后,我需要在数字选择器中输入计数。任何帮助,将不胜感激。谢谢。

4

3 回答 3

0
  1. 将 android:id 值添加到布局 XML 中的 NumberPicker 元素。

  2. 当您为 AlertDialog 扩展布局时,在扩展布局上调用 findViewById(),传入您在步骤 #1 中提供的 ID,并将结果转换为 NumberPicker。

  3. 在演示中有一个 NumberPicker 类对应于您的数字选择器小部件,该类包含一个 getCurrent() 方法,使用它来检索数字选择器的当前值。

于 2012-06-23T01:36:25.047 回答
0

试试这门课

公共类 DialogPicker 扩展 Picker {

public DialogPicker(Context context) {
    super(context);
    setContentView(R.layout.picker_dialog);
    NumberPicker numberPicker = (NumberPicker)findViewById(R.id.my_number_picker);
    //do whatever
    Button okbutton = (Button) findViewById(R.id.my_ok_button);
    //set your click listener
}

}

于 2012-06-23T01:37:26.130 回答
0

创建自定义对话框...

在 XML 中创建布局,称为 picker_dialog.xml 即:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"/>
    <com.mypackage.NumberPicker
         //set your layout
         />
    <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal">
         <Button
              //cancel button
              />
         <Button
              //Ok button
              />
    </LinearLayout>
</LinearLayout>

创建您的自定义对话框类

public class DialogPicker extends Picker {

    public DialogPicker(Context context) {
        super(context);
        setContentView(R.layout.picker_dialog);
        NumberPicker numberPicker = (NumberPicker)findViewById(R.id.my_number_picker);
        //do whatever
        Button okbutton = (Button) findViewById(R.id.my_ok_button);
        //set your click listener
    }
}

在您的活动中,只需运行:

PickerDialog pd = new PickerDialog(this);
pd.show();

祝你好运

于 2012-06-23T01:28:49.457 回答