Android实战第一篇——时钟+闹钟+计时器+秒表

这篇博客分享了Android实战项目,实现了一个包括时钟、闹钟、计时器和秒表功能的多功能时钟应用。作者详细介绍了布局设计、MainActivity的设置,以及每个功能模块的具体实现,如使用Handler刷新时钟、自定义数据类型存储闹钟、持久化数据保存、AlarmManager和BroadcastReceiver的使用。此外,还提到了在开发过程中遇到的问题及其解决方案。
摘要由CSDN通过智能技术生成

学习了快一学期的Android了,之前的知识点都是零散的学习的,只有当我们真正的去把他们用起来的时候才会发现难点,自己才会独立尝试去解决某个问题。接下来是我的一个简单的多功能时钟的小实战(视频资源https://pan.baidu.com/s/1mL8VUVC-9W9lO6IEpobDZg 密码:2ajv)

具体的效果可以参考手机上的时钟。

 

首先我们来看一看布局文件layout_main.xml

 

我们总的来看一下整个布局

 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <com.example.clock.TimeView
                    android:id="@+id/tabTime"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </com.example.clock.TimeView>

                <com.example.clock.AlarmView
                    android:id="@+id/tabAlarm"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
<span style="white-space:pre">		</span>……
                </com.example.clock.AlarmView>

                <com.example.clock.TimerView
                    android:id="@+id/tabTimer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
<span style="white-space:pre">		</span>……
                </com.example.clock.TimerView>

                <com.example.clock.StopWatchView
                    android:id="@+id/tabStopWatch"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
<span style="white-space:pre">		</span>……
                </com.example.clock.StopWatchView>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</FrameLayout>

 

整个布局整的是一个FrameLayout,我们在里面放了一个TabHost,接下来我们就可以在里面直接添加自己想要的布局了,可能初学者初一看会有那么一个疑问,就是<com.example.clock.……></com.example.clock.……>这个是什么东西??这是一个自定义的控件,我们创建的一个继承了LinearLayout的一个类(讲解可以参考这里http://blog.csdn.net/guozh/article/details/7662374),上面我们看到了四个这样的标签,表示我们有四个这样的Tab页面。关于布局的东西这里就不多讲了,之后会把我自己在学习过程中的一些不懂,以及相关的知识点上传到资源中,大家可以下载来看看。

 

这是完整的布局文件代码

 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <com.example.clock.TimeView
                    android:id="@+id/tabTime"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/tvTime"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:gravity="center"
                        android:textAppearance="?android:attr/textAppearanceLarge" />
                </com.example.clock.TimeView>

                <com.example.clock.AlarmView
                    android:id="@+id/tabAlarm"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >

                    <ListView
                        android:id="@+id/lvListAlarm"
                        android:layout_width="fill_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1" >
                    </ListView>

                    <Button
                        android:id="@+id/btnAddAlarm"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/add_alarm" >
                    </Button>
                </com.example.clock.AlarmView>

                <com.example.clock.TimerView
                    android:id="@+id/tabTimer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <EditText
                            android:id="@+id/etHour"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:inputType="number"
                            android:singleLine="true"
                            android:textAppearance="?android:attr/textAppearanceLarge" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text=":"
                            android:textAppearance="?android:attr/textAppearanceLarge" />

                        <EditText
                            android:id="@+id/etMin"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:inputType="number"
                            android:singleLine="true"
                      
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值