事件(4)
阿新 • • 發佈:2017-06-09
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; 1213 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)