Bonjour, je suis en dev sur Android.
J'ai le script suivant :
Code : 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 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View main = View.inflate(getApplicationContext(), R.layout.main, null); Button b = (Button) main.findViewById(R.id.my_button); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = getApplicationContext(); Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom_dialog); TextView text = (TextView) dialog.findViewById(R.id.text); text.setText("Hello, this is a custom dialog !"); ImageView image = (ImageView) dialog.findViewById(R.id.image); image.setImageResource(R.drawable.icon); dialog.show(); } }); setContentView(main); }
ici : le code pour custom_dialog :
et celui de main :
Code : 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 <?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_root" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="10dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="#FFF" /> </LinearLayout>
tout s'exécute bien jusqu'à ce que je clique sur le bouton, le système me dit qu'il rencontre une erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I'am a button !"/> </LinearLayout>
Besoin d'aide là-dessus.
Merci.
Partager