Android:无法打开对话框窗口/触发触摸事件

Android:无法打开对话框窗口/触发触摸事件,android,android-layout,Android,Android Layout,我有一个选项卡片段,在上面加载布局。此布局包含一个带有事件处理程序的按钮,但似乎从未触发该事件 public class SettingsFragmentTab extends Fragment { private Button mPickTime; private int mHour; private int mMinute; static final int TIME_DIALOG_ID = 0; @Override public View onCreateView

我有一个选项卡片段,在上面加载布局。此布局包含一个带有事件处理程序的按钮,但似乎从未触发该事件

public class SettingsFragmentTab extends Fragment
{
    private Button mPickTime;



    private int mHour;
private int mMinute;

static final int TIME_DIALOG_ID = 0;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    FrameLayout frame = (FrameLayout)inflater.inflate(R.layout.settings_list_content, container, false);

    mPickTime = (Button) frame.findViewById(R.id.pickTime);

    // add a click listener to the button
    mPickTime.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            getActivity().showDialog(TIME_DIALOG_ID);
        }
    });

        return frame;
}

// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(android.widget.TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMinute = minute;

        }
};
布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="right" >

         <TextView
             android:id="@+id/schedule"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_alignWithParentIfMissing="true"
             android:gravity="center_vertical"
             android:text="Schedule"
             android:textColor="#FFFFFF"
             android:textSize="20dp" />


         <Button
             android:id="@+id/pickTime"
             android:layout_width="50dp"
             android:layout_height="50dp"
             android:layout_toRightOf="@id/schedule"
             android:background="@drawable/addtime"
             android:gravity="right" />


         <ListView
             android:id="@+id/listSettings"
             android:layout_width="150dp"
             android:layout_height="wrap_content"
             android:layout_above="@id/app_name_tv"
             android:layout_below="@id/pickTime"
             android:divider="@android:color/transparent"
             android:dividerHeight="15.0sp" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="164dp"
        android:layout_height="67dp"
        android:layout_gravity="right"
        android:gravity="right" >

        <TextView
                android:id="@+id/timezone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:textSize="15dp"
                android:layout_alignWithParentIfMissing="true"
                android:layout_alignParentRight="true"
                android:text="Select Your Timezone: "
                 />

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/timezone"
            android:layout_alignParentRight="true"
            android:layout_below="@id/timezone"
            android:textAppearance="@drawable/spinner_style" />

    </RelativeLayout>
</FrameLayout>


我一遍又一遍地查看代码,但似乎找不到按钮“mPickTime”的事件未被触发的原因。

我会尝试在代码中添加类似于
finish()
的内容,而不是在
getActivity.showDialog(TIME\u DIALOG\u ID)
之后,为了确保这是您出错的地方,我尝试在事件处理程序中设置断点,并尝试打印toast消息。任何一种情况都不会触发事件处理程序。
public class SettingsFragmentTab extends Fragment
{
    private Button mPickTime;



    private int mHour;
private int mMinute;

static final int TIME_DIALOG_ID = 0;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    FrameLayout frame = (FrameLayout)inflater.inflate(R.layout.settings_list_content, container, false);

    mPickTime = (Button) frame.findViewById(R.id.pickTime);

    // add a click listener to the button
    mPickTime.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            getActivity().showDialog(TIME_DIALOG_ID);
        }
    });

        return frame;
}

// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(android.widget.TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMinute = minute;

        }
};