Android 警报对话框中的按钮不可单击

Android 警报对话框中的按钮不可单击,android,android-alertdialog,Android,Android Alertdialog,我有一个警报对话框,在对话框的布局中有一个按钮,我希望可以单击,但是当我使用onclick侦听器时,该按钮仍然不起作用 我的警报对话框就是这样建立起来的 AlertDialog.Builder alert = new AlertDialog.Builder(this); Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystem

我有一个警报对话框,在对话框的布局中有一个按钮,我希望可以单击,但是当我使用onclick侦听器时,该按钮仍然不起作用

我的警报对话框就是这样建立起来的

AlertDialog.Builder alert = new AlertDialog.Builder(this);

    Context mContext = getApplicationContext();
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.distro_editor_popup, (ViewGroup) findViewById(R.id.layout_root));

    txt_Name = (EditText) layout.findViewById(R.id.txt_LinuxName);
    txt_Image = (EditText) layout.findViewById(R.id.txt_ImageName);
    filemanger = (Button) layout.findViewById(R.id.fileselector); 

    txt_Name.setText(selected_Name);
    txt_Image.setText(selected_Image);

    final String oldName = selected_Name;
    final String oldImage = selected_Image;

    filemanger.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("file/*");
            startActivityForResult(intent,PICKFILE_RESULT_CODE);
        }
    });


    alert.setView(layout);

    alert.setPositiveButton(R.string.dialog_button_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String name = txt_Name.getText().toString();
            String image = txt_Image.getText().toString();

            // Make sure the user entered a name
            if (name.equals("")) {
                return;
            }

            if (!oldName.equals(name)) {
                // Name was changed so we have to delete the old one from the profiles first!
                profiles.remove(oldName);
            }

            if (!oldImage.equals(image)) {
                // Image name has changed so we rename the mounts and config files
                file_Rename(oldImage + ".mounts", image + ".mounts");
                file_Rename(oldImage + ".config", image + ".config");
            }

            profiles.put(name, image);
            lastSelected = name;

            fillSpinner();
            savePrefs();
        }
    });
    alert.setNegativeButton(R.string.dialog_button_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });

    alert.show();
然后对话框的XML布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>

<RelativeLayout android:layout_alignBaseline="@+id/layout_root" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="8sp" android:id="@+id/RelativeLayout1">
    <TextView
        android:id="@+id/label_Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/inputLabel_Name"
        android:layout_centerVertical="true"/>

    <EditText
        android:id="@+id/txt_LinuxName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/label_Name"
        android:hint="@string/hint_EnterName"
        android:textColor="#FF111111" >

        <requestFocus></requestFocus>
    </EditText>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/RelativeLayout3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/layout_root"
    android:layout_marginTop="8sp" >

    <TextView
        android:id="@+id/label_Image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="@string/launcher_Label_ImageName" />

    <EditText
        android:id="@+id/txt_ImageName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/fileselector"
        android:layout_toRightOf="@id/label_Image"
        android:textColor="#FF111111" >

        <requestFocus></requestFocus>
    </EditText>

    <Button
        android:id="@+id/fileselector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/txt_ImageName"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="..." />

</RelativeLayout>


您没有按否定按钮调用Disclose:

alert.setNegativeButton(R.string.dialog_button_cancel, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
          dialog.dismiss();
    }
});

至于积极的一面,你的
onClick
被解雇了吗?将日志语句放入并查看是否正确。

这只是一个猜测,因此可能是错误的,但是当您设置
onClickListener
时,请尝试将
fileSelector.setOnClickListener(new onClickListener)
行替换为
fileSelector.setOnClickListener(new View.onClickListener)

究竟什么不起作用,它是崩溃了,还是什么都没发生?对不起,我应该说得更清楚,什么都没发生,警报等都可以正常工作,但是当按下“文件选择器”按钮时,它不会做任何事情如果你没有或在你的意图之前敬酒,这会显示吗?不,它不会显示,看起来好像没有调用onclick?如果您使用
行,按钮是否工作?EditText可能因为某种原因而失去了所有焦点。添加此选项后,FileSelect按钮仍然无法单击,但谢谢你,我确实错过了这一点(尽管奇怪的是,没有它,其他所有功能都可以正常工作)正按钮和负按钮都可以正常工作,是警报对话框XML布局中的额外按钮“fileselector”不起作用您在这里看过了吗-