質問編集履歴

2

より分かりやすい質問内容にしました。

2018/06/19 03:32

投稿

kanchan000926
kanchan000926

スコア14

test CHANGED
@@ -1 +1 @@
1
- カスタムビュー、テキスト変更のコード簡略方法
1
+ カスタムレイアウトテキストをJavaで設定する際、より見やすく記述する方法
test CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  現在カスタムビューでレイアウトを使い回しています。
4
4
 
5
- レイアウト内にあるtextを設定する際のコードがmain.java内で複数になっており、見づらいので改善したいのですが、いい方法は無いでしょうか。
5
+ カスタムレイアウト内にあるtextを設定する際のコードがmain.java内で複数になっており、見づらいので改善したいのですが、いい方法は無いでしょうか。
6
6
 
7
- またカスタムビュー側の方も、こうしたらより見やすくなるよとう指摘がありましたらよろしくお願いします。
7
+ できれば一行で記述したいす。
8
8
 
9
9
  初歩的な質問ですが、ご鞭撻よろしくお願いします。
10
10
 
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- TextView textView2 = (findViewById(R.id.table1).findViewById(R.id.textView2));
31
+ TextView textView2 = findViewById(R.id.textView2));
32
32
 
33
33
  textView2.setText(R.string.text1_2);
34
34
 
@@ -46,221 +46,7 @@
46
46
 
47
47
 
48
48
 
49
- text = (TextView)layout.findViewById(R.id.textView3);
49
+ text = layout.findViewById(R.id.textView);
50
-
51
- text = (TextView)layout.findViewById(R.id.textView2);
52
-
53
- text = (TextView)layout.findViewById(R.id.textView6);
54
-
55
- text = (TextView)layout.findViewById(R.id.textView7);
56
-
57
- text = (TextView)layout.findViewById(R.id.textView29);
58
-
59
- text = (TextView)layout.findViewById(R.id.textView30);
60
-
61
- text = (TextView)layout.findViewById(R.id.textView5);
62
-
63
- text = (TextView)layout.findViewById(R.id.textView9);
64
-
65
- text = (TextView)layout.findViewById(R.id.textView8);
66
-
67
- text = (TextView)layout.findViewById(R.id.textView4);
68
-
69
- ```
70
-
71
-
72
-
73
-
74
-
75
- ```Java
76
-
77
- <android.support.constraint.ConstraintLayout
78
-
79
- xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
80
-
81
- android:layout_height="match_parent">
82
-
83
-
84
-
85
- <TableLayout
86
-
87
- android:id="@+id/tableLayout"
88
-
89
- android:layout_width="match_parent"
90
-
91
- android:layout_height="match_parent"
92
-
93
- android:layout_marginTop="48dp"
94
-
95
- android:background="@drawable/frame_style">
96
-
97
-
98
-
99
- <TableRow
100
-
101
- android:layout_width="match_parent"
102
-
103
- android:layout_height="match_parent"
104
-
105
- android:background="@drawable/frame_style">
106
-
107
-
108
-
109
- <TextView
110
-
111
- android:id="@+id/textView3"
112
-
113
- android:layout_width="match_parent"
114
-
115
- android:layout_height="wrap_content"
116
-
117
- android:background="@drawable/frame_style"
118
-
119
- android:textAlignment="center"
120
-
121
- android:textColor="#000"
122
-
123
- android:textSize="24sp"
124
-
125
- android:textStyle="bold" />
126
-
127
- </TableRow>
128
-
129
-
130
-
131
- <TableRow
132
-
133
- android:layout_width="match_parent"
134
-
135
- android:layout_height="match_parent"
136
-
137
- android:background="@drawable/frame_style">
138
-
139
-
140
-
141
- <TextView
142
-
143
- android:id="@+id/textView2"
144
-
145
- android:layout_width="wrap_content"
146
-
147
- android:layout_height="wrap_content"
148
-
149
- android:background="@drawable/frame_style"
150
-
151
- android:textAlignment="center"
152
-
153
- android:textColor="#000"
154
-
155
- android:textSize="18sp" />
156
-
157
-
158
-
159
- </TableRow>
160
-
161
-
162
-
163
- <TableRow
164
-
165
- android:layout_width="match_parent"
166
-
167
- android:layout_height="match_parent"
168
-
169
- android:background="@drawable/frame_style">
170
-
171
-
172
-
173
- <TextView
174
-
175
- android:id="@+id/textView6"
176
-
177
- android:layout_width="wrap_content"
178
-
179
- android:layout_height="match_parent"
180
-
181
- android:background="@drawable/frame_style"
182
-
183
- android:textAlignment="center"
184
-
185
- android:textColor="#000"
186
-
187
- android:textSize="24sp"
188
-
189
- android:textStyle="bold" />
190
-
191
-
192
-
193
- </TableRow>
194
-
195
-
196
-
197
- <TableRow
198
-
199
- android:layout_width="match_parent"
200
-
201
- android:layout_height="match_parent"
202
-
203
- android:background="@drawable/frame_style">
204
-
205
-
206
-
207
- <TextView
208
-
209
- android:id="@+id/textView7"
210
-
211
- android:layout_width="wrap_content"
212
-
213
- android:layout_height="wrap_content"
214
-
215
- android:background="@drawable/frame_style"
216
-
217
- android:textAlignment="textStart"
218
-
219
- android:textColor="#000"
220
-
221
- android:textSize="18sp" />
222
-
223
-
224
-
225
- </TableRow>
226
-
227
-
228
-
229
- <TableRow
230
-
231
- android:layout_width="match_parent"
232
-
233
- android:layout_height="match_parent"
234
-
235
- android:background="@drawable/frame_style">
236
-
237
-
238
-
239
- <TextView
240
-
241
- android:id="@+id/textView29"
242
-
243
- android:layout_width="wrap_content"
244
-
245
- android:layout_height="match_parent"
246
-
247
- android:background="@drawable/frame_style"
248
-
249
- android:textAlignment="center"
250
-
251
- android:textColor="#000"
252
-
253
- android:textSize="24sp"
254
-
255
- android:textStyle="bold" />
256
-
257
- </TableRow>
258
-
259
-
260
-
261
-
262
-
263
- </TableLayout>
264
50
 
265
51
 
266
52
 

1

必要情報が不足していると感じたため、追加情報の記載を行いました。レイアウトについて質問の簡易化についての質問でしたが、肝心のカスタムビューの中身についての記載を忘れていました。

2018/06/19 03:32

投稿

kanchan000926
kanchan000926

スコア14

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- android studio を利用し始めて1ヶ月の初心者です。
1
+ 利用し始めて1ヶ月の初心者です。
2
2
 
3
3
  現在カスタムビューでレイアウトを使い回しています。
4
4
 
@@ -67,3 +67,201 @@
67
67
  text = (TextView)layout.findViewById(R.id.textView4);
68
68
 
69
69
  ```
70
+
71
+
72
+
73
+
74
+
75
+ ```Java
76
+
77
+ <android.support.constraint.ConstraintLayout
78
+
79
+ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
80
+
81
+ android:layout_height="match_parent">
82
+
83
+
84
+
85
+ <TableLayout
86
+
87
+ android:id="@+id/tableLayout"
88
+
89
+ android:layout_width="match_parent"
90
+
91
+ android:layout_height="match_parent"
92
+
93
+ android:layout_marginTop="48dp"
94
+
95
+ android:background="@drawable/frame_style">
96
+
97
+
98
+
99
+ <TableRow
100
+
101
+ android:layout_width="match_parent"
102
+
103
+ android:layout_height="match_parent"
104
+
105
+ android:background="@drawable/frame_style">
106
+
107
+
108
+
109
+ <TextView
110
+
111
+ android:id="@+id/textView3"
112
+
113
+ android:layout_width="match_parent"
114
+
115
+ android:layout_height="wrap_content"
116
+
117
+ android:background="@drawable/frame_style"
118
+
119
+ android:textAlignment="center"
120
+
121
+ android:textColor="#000"
122
+
123
+ android:textSize="24sp"
124
+
125
+ android:textStyle="bold" />
126
+
127
+ </TableRow>
128
+
129
+
130
+
131
+ <TableRow
132
+
133
+ android:layout_width="match_parent"
134
+
135
+ android:layout_height="match_parent"
136
+
137
+ android:background="@drawable/frame_style">
138
+
139
+
140
+
141
+ <TextView
142
+
143
+ android:id="@+id/textView2"
144
+
145
+ android:layout_width="wrap_content"
146
+
147
+ android:layout_height="wrap_content"
148
+
149
+ android:background="@drawable/frame_style"
150
+
151
+ android:textAlignment="center"
152
+
153
+ android:textColor="#000"
154
+
155
+ android:textSize="18sp" />
156
+
157
+
158
+
159
+ </TableRow>
160
+
161
+
162
+
163
+ <TableRow
164
+
165
+ android:layout_width="match_parent"
166
+
167
+ android:layout_height="match_parent"
168
+
169
+ android:background="@drawable/frame_style">
170
+
171
+
172
+
173
+ <TextView
174
+
175
+ android:id="@+id/textView6"
176
+
177
+ android:layout_width="wrap_content"
178
+
179
+ android:layout_height="match_parent"
180
+
181
+ android:background="@drawable/frame_style"
182
+
183
+ android:textAlignment="center"
184
+
185
+ android:textColor="#000"
186
+
187
+ android:textSize="24sp"
188
+
189
+ android:textStyle="bold" />
190
+
191
+
192
+
193
+ </TableRow>
194
+
195
+
196
+
197
+ <TableRow
198
+
199
+ android:layout_width="match_parent"
200
+
201
+ android:layout_height="match_parent"
202
+
203
+ android:background="@drawable/frame_style">
204
+
205
+
206
+
207
+ <TextView
208
+
209
+ android:id="@+id/textView7"
210
+
211
+ android:layout_width="wrap_content"
212
+
213
+ android:layout_height="wrap_content"
214
+
215
+ android:background="@drawable/frame_style"
216
+
217
+ android:textAlignment="textStart"
218
+
219
+ android:textColor="#000"
220
+
221
+ android:textSize="18sp" />
222
+
223
+
224
+
225
+ </TableRow>
226
+
227
+
228
+
229
+ <TableRow
230
+
231
+ android:layout_width="match_parent"
232
+
233
+ android:layout_height="match_parent"
234
+
235
+ android:background="@drawable/frame_style">
236
+
237
+
238
+
239
+ <TextView
240
+
241
+ android:id="@+id/textView29"
242
+
243
+ android:layout_width="wrap_content"
244
+
245
+ android:layout_height="match_parent"
246
+
247
+ android:background="@drawable/frame_style"
248
+
249
+ android:textAlignment="center"
250
+
251
+ android:textColor="#000"
252
+
253
+ android:textSize="24sp"
254
+
255
+ android:textStyle="bold" />
256
+
257
+ </TableRow>
258
+
259
+
260
+
261
+
262
+
263
+ </TableLayout>
264
+
265
+
266
+
267
+ ```