事件(4)

时间事件监听器:OnTimeChangedListener 

  tp.setOnTimeChangedListener(new OnTimeChangedListener() {

    @Override
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
      String str=hourOfDay+":"+minute;
    }
  });

 1 package com.hh;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.widget.Button;
 6 import android.widget.EditText;
 7 import android.widget.RadioGroup;
 8 import android.widget.Spinner;
 9 import android.widget.TextView;
10 import android.widget.TimePicker;
11 import android.widget.TimePicker.OnTimeChangedListener;
12 
13 public class Click extends Activity{
14     private TextView tv;        //定义信息显示组件
15     private TimePicker tp;
16     
17     protected void onCreate(Bundle savedInstanceState) {
18         super.onCreate(savedInstanceState);
19         setContentView(R.layout.event);
20     
21         tv=(TextView)findViewById(R.id.tve1);            //取得文本显示组件
22     
23         tp=(TimePicker) findViewById(R.id.tp1);
24         tp.setOnTimeChangedListener(new OnTimeChangedListener() {
25             
26             @Override
27             public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
28                 String str=hourOfDay+":"+minute;
29             }
30         });
31 }
32         
代码示例
 1 <TextView
 2           android:id="@+id/tve1"
 3         android:layout_width="fill_parent" 
 4         android:layout_height="wrap_content" 
 5            android:background="#FF0000"
 6       />
 7        <TimePicker
 8                android:id="@+id/tp1"
 9             android:layout_width="fill_parent" 
10             android:layout_height="wrap_content"
11        />
xml配置文件

 

posted @ 2017-06-09 14:11  眼泪,还是流了  阅读(121)  评论(0编辑  收藏  举报