回答編集履歴
1
追記
test
CHANGED
@@ -5,3 +5,115 @@
|
|
5
5
|
参考: [Kotlin Android Extensions syntheticsのdeprecatedに伴う対応 - Qiita](https://qiita.com/taigen/items/116ff3856eab6634e47b)
|
6
6
|
|
7
7
|
参考: [https://teratail.com/questions/330555#reply-456902](https://teratail.com/questions/330555#reply-456902)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
### findViewById の場合
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```diff
|
20
|
+
|
21
|
+
+ val hitText = findViewById<TextView>(R.id.hitText)
|
22
|
+
|
23
|
+
hitText.text = getString(R.string.hit_text)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
+ val loseText = findViewById<TextView>(R.id.loseText)
|
28
|
+
|
29
|
+
loseText.text = getString(R.string.lose_text)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
---
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
### view binding の場合
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
app/build.gradle の android { 〜 } に viewBinding を追加
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```diff
|
48
|
+
|
49
|
+
android {
|
50
|
+
|
51
|
+
// 略
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
+ viewBinding {
|
56
|
+
|
57
|
+
+ enabled = true
|
58
|
+
|
59
|
+
+ }
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
MainActivity.kt を修正
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```diff
|
72
|
+
|
73
|
+
-import **kotlinx**.android.synthetic.main.activity_main.*
|
74
|
+
|
75
|
+
+import com.example.highandlow.databinding.ActivityMainBinding
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class MainActivity : AppCompatActivity() {
|
80
|
+
|
81
|
+
+ private lateinit var binding: ActivityMainBinding
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// 略
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
90
|
+
|
91
|
+
super.onCreate(savedInstanceState)
|
92
|
+
|
93
|
+
- setContentView(R.layout.activity_main)
|
94
|
+
|
95
|
+
+ binding = ActivityMainBinding.inflate(layoutInflater)
|
96
|
+
|
97
|
+
+ setContentView(binding.root)
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
override fun onResume() {
|
104
|
+
|
105
|
+
// 略
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
- **hitText**.text = getString(R.string.hit_text)
|
110
|
+
|
111
|
+
- **loseText**.text = getString(R.string.lose_text)
|
112
|
+
|
113
|
+
+ binding.hitText.text = getString(R.string.hit_text)
|
114
|
+
|
115
|
+
+ binding.loseText.text = getString(R.string.lose_text)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
```
|