1. 程式人生 > >事件(4)

事件(4)

cte listener create content images pac ogr round rri

時間事件監聽器:OnTimeChangedListener

  tp.setOnTimeChangedListener(new OnTimeChangedListener() {

[email protected]
    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配置文件

技術分享

事件(4)