我接近我想要的,对话框打开,小时和分钟号码选择器出现,但它们没有上下数字滚动.我也无法使用d出的键盘编辑数字.我尝试添加一个onValueChange侦听器,但是当我使用键盘时它没有生成任何事件.
谁能提供有关如何解决此问题的建议?到目前为止,我已经注意到,我尝试对某些活动中的小部件或特定类中不支持的片段进行了很多 *** 作.
以下是相关代码和图片的片段:
我有一个带有两个按钮的ClockActivity类:
...public class ClockActivity extends ActionBaractivity {...@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_clock); // define gui objects ... mWorkForTime = (button)findVIEwByID(R.ID.work_for_time); mBreakForTime = (button)findVIEwByID(R.ID.break_for_time); // Add Listeners for the work for/break for buttons mWorkForTime.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Bring up the picker fragment DialogFragment newFragment = TimePickerFragment.newInstance(R.string.work_Title); newFragment.show(getSupportFragmentManager(),"WorkTimePicker"); } }); mBreakForTime.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Bring up the picker fragment DialogFragment newFragment = TimePickerFragment.newInstance(R.string.break_Title); newFragment.show(getSupportFragmentManager(),"BreakTimePicker"); } }); ...
TimePickerFragment类扩展了DialogFragment:
public class TimePickerFragment extends DialogFragment { // Setup the time pickers private NumberPicker mHourPicker; private NumberPicker mMinutePicker; public static TimePickerFragment newInstance(int Title) { TimePickerFragment fragment = new TimePickerFragment(); Bundle args = new Bundle(); args.putInt("Title",Title); fragment.setArguments(args); return fragment; } @OverrIDe public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); int Title = getArguments().getInt("Title"); LayoutInflater inflater = getActivity().getLayoutInflater(); VIEw vIEw = (VIEw)inflater.inflate(R.layout.activity_time_picker,null); // Initialize the pickers mHourPicker = (NumberPicker)vIEw.findVIEwByID(R.ID.hours_picker); mMinutePicker = (NumberPicker)vIEw.findVIEwByID(R.ID.minutes_picker); mHourPicker.setMinValue(0); mMinutePicker.setMinValue(0); mHourPicker.setMaxValue(24); mMinutePicker.setMaxValue(59); Dialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(Title) .setVIEw(inflater.inflate(R.layout.activity_time_picker,null)) .setNegativebutton(R.string.negate,new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog,int which) { ((ClockActivity) getActivity()).doNegativeTimeDialogClick(); } }) .setPositivebutton(R.string.confirm,int which) { ((ClockActivity) getActivity()).doPositiveTimeDialogClick(); } }) .create(); return alertDialog; }}
以下是DialogFragment视图的XML
<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <TextVIEw androID:layout_wIDth="0dp" androID:layout_weight="1" androID:layout_height="wrap_content" androID:gravity="center" androID:text="@string/hours" androID:textSize="24sp" androID:textStyle="bold"/> <TextVIEw androID:layout_wIDth="0dp" androID:layout_weight="1" androID:layout_height="wrap_content" androID:gravity="center" androID:text="@string/minutes" androID:textSize="24sp" androID:textStyle="bold"/> </linearLayout> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <NumberPicker androID:ID="@+ID/hours_picker" androID:layout_wIDth="0dp" androID:layout_weight="1" androID:layout_height="wrap_content"/> <NumberPicker androID:ID="@+ID/minutes_picker" androID:layout_wIDth="0dp" androID:layout_weight="1" androID:layout_height="wrap_content"/> </linearLayout> </linearLayout>
这是当前 *** 作的图像:
http://i.imgur.com/4UiSLcn.png
这是我想要的:
http://www.i-programmer.info/images/stories/Core/Android/Pickers/ten.gif
当我尝试使用软键盘编辑NumberPicker时,我在控制台上看到的是一些输出:
01-02 16:10:46.559 18438-18438/com.example.androID.worktimer W/IinputConnectionWrapper﹕ beginBatchEdit on inactive inputConnection01-02 16:10:46.569 18438-18438/com.example.androID.worktimer W/IinputConnectionWrapper﹕ endBatchEdit on inactive inputConnection解决方法 您必须为选择器提供您要选择的数组.
String[] myStringArray = new String[]{"a","b","c"}; mMinutePicker.setMinValue(0); mMinutePicker.setMaxValue(myStringArray.length - 1); mMinutePicker.setdisplayedValues(myStringArray);
并改变
Dialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(Title) .setVIEw(inflater.inflate(R.layout.activity_time_picker,null))
至
Dialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle(Title).setVIEw(vIEw)
您正在再次膨胀视图.
总结以上是内存溢出为你收集整理的android – NumberPicker在DialogFragment中不起作用全部内容,希望文章能够帮你解决android – NumberPicker在DialogFragment中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)