Android对话框没有显示出来

时间:2013-08-23 13:50:51

标签: android dialog

我有一个TextView,点击它后会打开一个对话框,其中会使用日期和时间选择器作为其视图。

datetimepicker.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的文本和用户设置的时间在对话框上。

你有什么建议吗? TIA。

1 个答案:

答案 0 :(得分:0)

你忘了打电话了

Dialog.show()