Read Android from entry to entry (14)-time Selector

Source: Internet
Author: User

Read Android from entry to entry (14)-time Selector
TimePicker)

Java. lang. Object;
Android. view. View;
Android. view. ViewGroup;
Android. widget. FrameLayout;
Android. widget. TimePicker;

TimePicker Class Method

TimePick example

Complete: http://download.csdn.net/detail/sweetloveft/9410965

The following program mainly learns the usage of TimePicker. The method of not using Calendar is the same as that in the previous article. Pay attention to the 24-hour time setting problem.

1. MainActivity. java

 

Package com. sweetlover. activity; import com. sweetlover. timepickerdemo. r; import android. app. activity; import android. OS. bundle; import android. widget. textView; import android. widget. timePicker; import android. widget. timePicker. onTimeChangedListener; public class MainActivity extends Activity {private TextView textView = null; private TimePicker timePicker = null; private int curHour = 8, curMinute = 30; @ override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. activity_main); textView = (TextView) findViewById (R. id. textView1); timePicker = (TimePicker) findViewById (R. id. timePicker1); timePicker. setIs24HourView (false); timePicker. setOnTimeChangedListener (new TimeChangedListener ();} private class TimeChangedListener implements OnTimeChangedListener {@ Overridepublic void onTimeChanged (TimePicker view, int hourOfDay, int minute) {// TODO Auto-generated method stubcurHour = hourOfDay; curMinute = minute; textView. setText ("current time:" + curHour + "Hour" + curMinute + "Minute ");}}}
2. activity_main.xml
<!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="30dp" android:orientation="vertical">    <timepicker android:id="@+id/timePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content">    <textview android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margintop="30dp" android:textappearance="?android:attr/textAppearanceMedium"></textview></timepicker></linearlayout>
3. AndroidManifest. xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sweetlover.timepickerdemo" android:versioncode="1" android:versionname="1.0">    <uses-sdk android:minsdkversion="8" android:targetsdkversion="19">    <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">        <activity android:name="com.sweetlover.activity.MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN">                <category android:name="android.intent.category.LAUNCHER">            </category></action></intent-filter>        </activity>    </application></uses-sdk></manifest>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.