Vania Lamas
- Forum posts: 1
Feb 24, 2014, 5:15:21 PM via Website
Feb 24, 2014 5:15:21 PM via Website
Hi.
I'm creating an app and I have a radio group with 4 buttons. I decided to customise it and instead of the traditional view, I decided to use some png images. One for when that radio button is selected and another for when it is not selected.
The problem is that the image changes to the activated, but it never goes back to not activated image.
XML Code:
Main XML Code:
I'm creating an app and I have a radio group with 4 buttons. I decided to customise it and instead of the traditional view, I decided to use some png images. One for when that radio button is selected and another for when it is not selected.
The problem is that the image changes to the activated, but it never goes back to not activated image.
XML Code:
1<?xml version="1.0" encoding="utf-8"?>
2<selector xmlns:android=(...)>
3 <item android:drawable="@drawable/camon" android:state_checked="true" android:state_pressed="false" />
4 <item android:drawable="@drawable/camoff" android:state_checked="false" android:state_pressed="false" />
5 <item android:drawable="@drawable/camon" android:state_checked="true" android:state_pressed="true" />
6 <item android:drawable="@drawable/camoff" android:state_checked="false" android:state_pressed="true" />
7</selector>
2<selector xmlns:android=(...)>
3 <item android:drawable="@drawable/camon" android:state_checked="true" android:state_pressed="false" />
4 <item android:drawable="@drawable/camoff" android:state_checked="false" android:state_pressed="false" />
5 <item android:drawable="@drawable/camon" android:state_checked="true" android:state_pressed="true" />
6 <item android:drawable="@drawable/camoff" android:state_checked="false" android:state_pressed="true" />
7</selector>
Main XML Code:
1<RadioGroup
2 android:id="@+id/radioGroup1"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:orientation="vertical" >
6
7 <TableRow
8 android:id="@+id/tableRow3"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:gravity="center" >
12
13 <RadioButton
14 android:id="@+id/radio0"
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content"
17 android:checked="true"
18 android:text=""
19 android:background="@drawable/radio_1"
20 android:button="@null" />
21
22 <RadioButton
23 android:id="@+id/radio1"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:background="@drawable/radio_2"
27 android:text=""
28 android:button="@null" />
29
30 </TableRow>
31
32 <TableRow
33 android:id="@+id/tableRow4"
34 android:layout_width="wrap_content"
35 android:layout_height="wrap_content"
36 android:gravity="center" >
37
38 <TextView
39 android:id="@+id/TextView01"
40 android:layout_width="match_parent"
41 android:layout_height="wrap_content"
42 android:text="View 1"
43 android:textAppearance="?android:attr/textAppearanceSmall" />
44
45 <TextView
46 android:id="@+id/textView2"
47 android:layout_width="match_parent"
48 android:layout_height="wrap_content"
49 android:text="View 2"
50 android:textAppearance="?android:attr/textAppearanceSmall" />
51 </TableRow>
52
53 <TableRow
54 android:id="@+id/tableRow1"
55 android:layout_width="match_parent"
56 android:layout_height="wrap_content"
57 android:gravity="center" >
58
59 <RadioButton
60 android:id="@+id/radio2"
61 android:layout_width="wrap_content"
62 android:layout_height="wrap_content"
63 android:background="@drawable/radio_3"
64 android:text=""
65 android:button="@null" />
66
67 <RadioButton
68 android:id="@+id/radio3"
69 style="@drawable/button_radio"
70 android:layout_width="wrap_content"
71 android:layout_height="wrap_content"
72 android:background="@drawable/radio_4"
73 android:text=""
74 android:button="@null" />
75
76 </TableRow>
77
78 <TableRow
79 android:id="@+id/tableRow4"
80 android:layout_width="wrap_content"
81 android:layout_height="wrap_content"
82 android:gravity="center" >
83
84 <TextView
85 android:id="@+id/TextView03"
86 android:layout_width="match_parent"
87 android:layout_height="wrap_content"
88 android:text="View 3"
89 android:textAppearance="?android:attr/textAppearanceSmall" />
90
91 <TextView
92 android:id="@+id/textView4"
93 android:layout_width="match_parent"
94 android:layout_height="wrap_content"
95 android:text="View 4"
96 android:textAppearance="?android:attr/textAppearanceSmall" />
97 </TableRow>
98 </RadioGroup>
2 android:id="@+id/radioGroup1"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:orientation="vertical" >
6
7 <TableRow
8 android:id="@+id/tableRow3"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:gravity="center" >
12
13 <RadioButton
14 android:id="@+id/radio0"
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content"
17 android:checked="true"
18 android:text=""
19 android:background="@drawable/radio_1"
20 android:button="@null" />
21
22 <RadioButton
23 android:id="@+id/radio1"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:background="@drawable/radio_2"
27 android:text=""
28 android:button="@null" />
29
30 </TableRow>
31
32 <TableRow
33 android:id="@+id/tableRow4"
34 android:layout_width="wrap_content"
35 android:layout_height="wrap_content"
36 android:gravity="center" >
37
38 <TextView
39 android:id="@+id/TextView01"
40 android:layout_width="match_parent"
41 android:layout_height="wrap_content"
42 android:text="View 1"
43 android:textAppearance="?android:attr/textAppearanceSmall" />
44
45 <TextView
46 android:id="@+id/textView2"
47 android:layout_width="match_parent"
48 android:layout_height="wrap_content"
49 android:text="View 2"
50 android:textAppearance="?android:attr/textAppearanceSmall" />
51 </TableRow>
52
53 <TableRow
54 android:id="@+id/tableRow1"
55 android:layout_width="match_parent"
56 android:layout_height="wrap_content"
57 android:gravity="center" >
58
59 <RadioButton
60 android:id="@+id/radio2"
61 android:layout_width="wrap_content"
62 android:layout_height="wrap_content"
63 android:background="@drawable/radio_3"
64 android:text=""
65 android:button="@null" />
66
67 <RadioButton
68 android:id="@+id/radio3"
69 style="@drawable/button_radio"
70 android:layout_width="wrap_content"
71 android:layout_height="wrap_content"
72 android:background="@drawable/radio_4"
73 android:text=""
74 android:button="@null" />
75
76 </TableRow>
77
78 <TableRow
79 android:id="@+id/tableRow4"
80 android:layout_width="wrap_content"
81 android:layout_height="wrap_content"
82 android:gravity="center" >
83
84 <TextView
85 android:id="@+id/TextView03"
86 android:layout_width="match_parent"
87 android:layout_height="wrap_content"
88 android:text="View 3"
89 android:textAppearance="?android:attr/textAppearanceSmall" />
90
91 <TextView
92 android:id="@+id/textView4"
93 android:layout_width="match_parent"
94 android:layout_height="wrap_content"
95 android:text="View 4"
96 android:textAppearance="?android:attr/textAppearanceSmall" />
97 </TableRow>
98 </RadioGroup>
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.