Reputation: 161
I have some code that creates a popup and assign it an XML layout that has two ImageView items in it.
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 has the two ImageView items
How can I add click listeners to those two items? When I try doing it the same way as any other button, findViewById() returns a null value
XML code
<?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>
Upvotes: 1
Views: 187
Reputation: 76458
Try this:
popupWindow.findViewById(R.id.yourId);
or if you want:
noteChoices.findViewById(R.id.yourId);
Upvotes: 1