繁体   English   中英

如何在AlertDialog.Builder中访问ImageView?

[英]How can I access an ImageView inside of AlertDialog.Builder?

我有一些代码可以创建一个弹出窗口,并为其分配一个具有两个ImageView项的XML布局。

popupWindow.setTitle("New note");
popupWindow.setMessage("choose the type of note to create");

View noteChoices = inflater.inflate(R.layout.addnotepopup, null);
popupWindow.setView(noteChoices);

popupWindow.setPositiveButton(null, null);

popupWindow.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        //
    }
});

popupWindow.show();

addnotepopup.xml具有两个ImageView项

如何在这两个项目中添加点击监听器? 当我尝试使用与其他按钮相同的方法时,findViewById()返回一个空值

XML代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:weightSum="2" >

    <ImageView
        android:id="@+id/recordnoteoption"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingBottom="10dp" 
        android:src="@drawable/medium_mic"
        android:layout_weight="1" />

        <ImageView
            android:id="@+id/typenoteoption"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="10dp"
            android:paddingBottom="10dp" 
            android:src="@drawable/medium_keyboard"
            android:layout_weight="1" />

</LinearLayout>

尝试这个:

 popupWindow.findViewById(R.id.yourId);

或者,如果您想:

  noteChoices.findViewById(R.id.yourId);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM