这里有几件事: 1. 设置一个侦听器以获取从选择器中选择的值,然后获取时间选择器的值:
public class MainActivity extends Activity{
Integer[] numbers = new Integer[]{0,1,2,3,4,5,6,7,8};
final TimePicker tp = (TimePicker)findViewById(R.id.timePicker1);
tp.setIs24HourView(true);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,
android.R.layout.simple_list_item_single_choice, numbers);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
int index = arg0.getSelectedItemPosition();
switch(index)
{
case 0:
int min = tp.getCurrentMinute();
int hour = tp.getCurrentHour();
//Do your calculations here etc
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
这可能对你也有帮助,如何为时间选择器设置监听器,(如果有人可以帮助我并编辑它,不能让它正确格式化):
final TimePicker tp = (TimePicker)findViewById(R.id.timePicker1);
TimePicker.OnTimeChangedListener listen = new
TimePicker.OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
//do some calculations with hourOfDay and minute
}
};
tp.setOnTimeChangedListener(听);