Hello
J'essaie de faire une zone cliquable sur un imageView avec un RelativeLayout depuis un DialogFragment. Mon Dialogfragment est appelé depuis mon MainActivity


J'ai l'erreur suivante :

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Auriez-vous une idée ?

code du DialogFragment :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
RelativeLayout rl = (RelativeLayout) getActivity().findViewById( R.id.clikeable1 );
        rl.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity().getApplicationContext(), "toto", Toast.LENGTH_SHORT).show();
            }
        });


code du relativelayout

Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
 
 
    <TextView
 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="290dp"
        android:layout_marginTop="110dp"
        android:text="Entrez le code étape" />
   <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/password_keyboard" />
 
    <ImageView
        android:id="@+id/passwordKo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="295dp"
        android:layout_marginTop="170dp"
        app:srcCompat="@android:drawable/presence_invisible" />
 
    <ImageView
        android:id="@+id/passwordOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="405dp"
        android:layout_marginTop="170dp"
        app:srcCompat="@android:drawable/presence_invisible" />
 
    <EditText
        android:id="@+id/passwordEtape"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="false"
        android:layout_marginTop="35dp"
        android:ems="3"
        android:inputType="numberSigned"
        android:maxLength="4" />
 
 
    <RelativeLayout
        android:layout_width="350dp"
        android:layout_height="350dp"
        android:id="@+id/clikeable1"
        android:onClick="action1"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignBottom="@+id/imageView2"/>
 
</RelativeLayout>

Thank you. Max