Java 如何访问AlertDialog.Builder内部的ImageView?
我有一些代码可以创建一个弹出窗口,并为其分配一个XML布局,其中包含两个ImageView项Java 如何访问AlertDialog.Builder内部的ImageView?,java,android,android-alertdialog,Java,Android,Android Alertdialog,我有一些代码可以创建一个弹出窗口,并为其分配一个XML布局,其中包含两个ImageView项 popupWindow.setTitle("New note"); popupWindow.setMessage("choose the type of note to create"); View noteChoices = inflater.inflate(R.layout.addnotepopup, null); popupWindow.setView(noteChoices); popupW
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);
试试这个:
popupWindow.findViewById(R.id.yourId);
或者,如果您愿意:
noteChoices.findViewById(R.id.yourId);
请为
R.layout.addnotepopup
放置xml布局?另外,请将用于findViewById
的代码放入R.layout.addnotepopup
的xml布局?还将用于findViewById
的代码放入?使用noteChoices有效,我以前尝试过使用popupWindow.findViewById(),但不起作用。。。谢谢使用noteChoices有效,我以前尝试过使用popupWindow.findViewById(),但不起作用。。。谢谢