开发者

How do you call a timepicker from a preference activity?

Can you tell me how to call a time picker from a preference activity?

Can you show the needed manifest.xml, layout.xml and code inside the preference activity and any other needed开发者_开发问答 files to call the time picker?


To add a TimePicker to a standar Activity, add the TimePicker widget to your layout like this:

<TimePicker android:id="@+id/timePicker" android:layout_below="@+id/timePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

Next, have your activity implement OnTimeChangedListener. Then you'll need to add the following method to your activity:

private void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    // Do something with the time here
}

To call a TimePicker from a PreferenceActivity, you may want to consider popping up a dialog to handle the selection of time from the user. Have a look at this class which shows an implementation of doing so: http://code.google.com/p/onlinemanager/source/browse/trunk/WebViewer/src/fr/webviewer/activity/PreferenceActivity.java?r=76

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜