我有一个TextView
,一旦我单击它,将打开一个对话框,该对话框使用日期和时间选择器作为其视图。
日期时间选择器.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</DatePicker>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TimePicker>
<LinearLayout
android:id="@+id/setcancel"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SET" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CANCEL" />
</LinearLayout>
</LinearLayout>
这是代码TextView.OnClickListener
final TextView startTime = (TextView) getActivity().findViewById(R.id.textView3);
startTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.datetimepicker);
dialog.setTitle("Set Date and Time");
Button set = (Button) dialog.findViewById(R.id.button1);
Button cancel = (Button) dialog.findViewById(R.id.button2);
final TimePicker tp = (TimePicker)dialog.findViewById(R.id.timePicker1);
tp.setCurrentHour(Calendar.HOUR_OF_DAY);
tp.setCurrentMinute(Calendar.MINUTE);
tp.setOnTimeChangedListener(new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
hour = hourOfDay;
min = minute;
}
});
set.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startTime.setText(Integer.toString(hour)+ ";" + Integer.toString(min));
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
}
});
问题是,一旦我点击TextView
它什么都不做,我的意思是什么都没有发生,我想TextView
在对话框上点击 OK 按钮后设置用户设置的时间的文本。
你有什么建议吗?TIA。