我有一个按钮,点击必须生成一个对话框,其中包含一个数字选择器,和确定-取消按钮。我正在使用Android2.3.3(而不是API 11),所以我已经从这里下载了号码选择器。它很好用。单击“确定”按钮后,我需要在数字选择器中输入计数。任何帮助都将不胜感激。谢谢。
发布于 2012-06-22 17:28:49
创建一个定制对话框..。
用XML创建布局,称为picker_dialog.xml ie:
<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-22 17:36:25
发布于 2012-06-22 17:37:26
试试这门课
公共类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
}
}
https://stackoverflow.com/questions/11166001
复制相似问题