Bonjour à tous.
Désolé d'avance pour le paté, mais je vois pas comment synthétiser ma question.
Je travaille actuellement sur une application, qui, pour contexte, ressemble à ceci :
On s'aperçoit très vite que deux modules possèdent les même caractéristiques :
- Même titre(nom du composant mis de côté)
- Même icône
- Même emplacement texte
- Même bouton "Réappro"
etc..
J'ai donc copié mon bloc XML dans un layout externe, qui est donc :
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- h_2D_SCAN --><RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="-10dp"> <ImageView android:id="@+id/lotNumberTextViewBackground" android:layout_width="276dp" android:layout_height="32dp" android:layout_marginStart="65dp" android:layout_marginTop="36dp" android:background="@drawable/edittext_borders_disable" android:contentDescription="@string/describe" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"> <TextView android:id="@+id/lotNumberTitleText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="44dp" android:fontFamily="@font/nats" android:text="@string/hLotNumber" android:textAllCaps="true" android:textColor="@color/black" android:textSize="21sp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:contentDescription="@string/describe" android:src="@drawable/ic_scan_2d" /> <TextView android:id="@+id/lotNumberConsultationText" android:layout_width="235dp" android:layout_height="27dp" android:layout_marginStart="55dp" android:layout_marginTop="38dp" android:text="" android:textAllCaps="true" android:textSize="18sp" /> <TextView android:layout_width="130dp" android:layout_height="22dp" android:layout_marginStart="50dp" android:layout_marginTop="60dp" android:fontFamily="@font/nats" android:text="@string/lastRestock" android:textAllCaps="true" android:textColor="@color/black" android:textSize="16sp" /> <TextView android:id="@+id/lotNumberLastRestock" android:layout_width="130dp" android:layout_height="22dp" android:layout_marginStart="180dp" android:layout_marginTop="60dp" android:fontFamily="@font/nats" android:text="" android:textAllCaps="true" android:textColor="@color/black" android:textSize="16sp" /> <ImageButton android:id="@+id/lotNumberRestockButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="154dp" android:layout_marginTop="88dp" android:background="@color/alpha" android:contentDescription="@string/describe" android:onClick="showOverlay" android:src="@drawable/ic_restock" tools:ignore="TouchTargetSizeCheck" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="188dp" android:layout_marginTop="89dp" android:fontFamily="@font/pragatinarrow" android:text="@string/restock" android:textAllCaps="true" android:textColor="@color/white" android:textSize="20sp" /> </RelativeLayout> </RelativeLayout><!-- h_2D_SCAN --> </RelativeLayout>
Et, que j'appelle, dans mon ActivityLayout, par ce biais :
et, un peu plus bas, par ce biais :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <include android:id="@+id/machinenumberHConsultation" layout="@layout/scan2d_layout"/>
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <include android:id="@+id/machinenumberDiskConsultation" layout="@layout/scan2d_layout"/>
Jusqu'ici, tout va bien, les view s'affichent sans problème. J'interviens par le code pour changer certains affichages(images et texte), ce que je suis arrivé à faire en me "projettant" dans le include via ce moyen (en Java cette fois) :
ça marche du tonnerre jusqu'ici, cependant : le bouton "Réappro" présent 3x dans l'image ci-haut effectue pour action :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 View hLotGroup = findViewById(R.id.machinenumberHConsultation); TextView hLotNumber = hLotGroup.findViewById(R.id.lotNumberConsultationText);
Et c'est là que ça coince :
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public void showOverlay(View view) { int viewID = view.getId(); boolean bContinue = false; view.startAnimation(onClick); View overlay = findViewById(R.id.valveAssemblyOverlay); TextView mOverlayMachineNumber = findViewById(R.id.machineNumberOverlayMachineNumberText); // AFFICHAGE DE NUMERO DE LOT GRISÉ TextView mOverlayPartTypeText = findViewById(R.id.machineNumberRestockPartText); ImageView mRestockPartIcon = findViewById(R.id.machineNumberOverlayRestockPartIcon); switch (viewID) { case R.id.lotNumberRestockButton : // PROBLEME ICI bContinue = true; iRestockPartType = 0; mOverlayPartTypeText.setText(R.string.hLotRestock); iNumberLotLength = 13; break; case R.id.celgardNumberRestockButton: bContinue = true; iRestockPartType = 1; mOverlayPartTypeText.setText(R.string.celgardLotRestock); mRestockPartIcon.setImageResource(R.drawable.ic_keyboard_icon); iNumberLotLength = 7; break; case R.id.lotNumberRestockButton: // PROBLEME ICI bContinue = true; mOverlayPartTypeText.setText(R.string.diskLotRestock); iRestockPartType = 2; iNumberLotLength = 12; break; } if (bContinue) { getWindow().setStatusBarColor(getResources().getColor(R.color.orange_bic_smoked, this.getTheme())); // on change la couleur de la status bar pour correspondre à l'overlay // sMachineNumber = getIntent().getStringExtra("machineNumber"); mOverlayMachineNumber.setText(sMachineNumber); overlay.setVisibility(View.VISIBLE); overlayLotNumberEditText.requestFocus(); } else { view.startAnimation(shake); Toast.makeText(ValveAssemblyMachineNumberActivity.this, sScanError, Toast.LENGTH_SHORT).show(); } }
Mon overlay n'est pas le même en fonction de la view utilisée en argument de la méthode "showOverlay".
J'ai un switch sur l'ID(en int) que j'obtiens via
Sauf que, dans mon cas, désormais mon view.getId() est identique dans les deux modules : je ne peux pas "cast" cette demande d'id dans l'include comme je le fais via le view hLotGroup
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 int viewID = view.getId() switch (viewID) { Affiche le contenu de l'overlay en personalisant les différents champs en fonction de la view utilisée }
Quelqu'un aurait un tour de passe-passe à proposer afin de distinguer mes deux boutons "Réappro." lors de mon switch ? :smile:
Merci d'avance,
Phae
Partager