質問編集履歴

1

MainActivity.kt、画面レイアウトxmlを掲載します。

2021/10/24 04:14

投稿

rasum
rasum

スコア21

test CHANGED
File without changes
test CHANGED
@@ -125,3 +125,215 @@
125
125
  2021-10-24 11:39:55.847 11288-11288/PACKAGE D/MyApp: Dialog: onStart
126
126
 
127
127
  ```
128
+
129
+
130
+
131
+ MainActivity
132
+
133
+ ```
134
+
135
+ import androidx.appcompat.app.AppCompatActivity
136
+
137
+ import android.os.Bundle
138
+
139
+ import net.sytes.rokkosan.myalertdialog.databinding.ActivityMainBinding
140
+
141
+
142
+
143
+ class MainActivity : AppCompatActivity() {
144
+
145
+
146
+
147
+ private lateinit var viewBinding: ActivityMainBinding
148
+
149
+ val myDialogFragment = MyDialogFragment()
150
+
151
+
152
+
153
+ override fun onCreate(savedInstanceState: Bundle?) {
154
+
155
+ super.onCreate(savedInstanceState)
156
+
157
+ setContentView(R.layout.activity_main)
158
+
159
+
160
+
161
+ // set View Binding
162
+
163
+ viewBinding = ActivityMainBinding.inflate(layoutInflater)
164
+
165
+ setContentView(viewBinding.root)
166
+
167
+
168
+
169
+ viewBinding.btnOpenDialog.setOnClickListener {
170
+
171
+ myDialogFragment.show(supportFragmentManager, "my")
172
+
173
+
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ ```
182
+
183
+
184
+
185
+ activity_main.xml
186
+
187
+ ```
188
+
189
+ <?xml version="1.0" encoding="utf-8"?>
190
+
191
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
192
+
193
+ xmlns:app="http://schemas.android.com/apk/res-auto"
194
+
195
+ xmlns:tools="http://schemas.android.com/tools"
196
+
197
+ android:layout_width="match_parent"
198
+
199
+ android:layout_height="match_parent"
200
+
201
+ tools:context=".MainActivity">
202
+
203
+
204
+
205
+ <Button
206
+
207
+ android:id="@+id/btnOpenDialog"
208
+
209
+ android:layout_width="wrap_content"
210
+
211
+ android:layout_height="wrap_content"
212
+
213
+ android:text="@string/btn_open_dialog"
214
+
215
+ android:visibility="visible"
216
+
217
+ app:layout_constraintBottom_toBottomOf="parent"
218
+
219
+ app:layout_constraintLeft_toLeftOf="parent"
220
+
221
+ app:layout_constraintRight_toRightOf="parent"
222
+
223
+ app:layout_constraintTop_toTopOf="parent"
224
+
225
+ tools:visibility="visible" />
226
+
227
+
228
+
229
+ <TextView
230
+
231
+ android:id="@+id/tvData1"
232
+
233
+ android:layout_width="wrap_content"
234
+
235
+ android:layout_height="wrap_content"
236
+
237
+ android:text="TextView"
238
+
239
+ app:layout_constraintBottom_toTopOf="@id/tvData2"
240
+
241
+ app:layout_constraintHorizontal_bias="0.501"
242
+
243
+ app:layout_constraintLeft_toLeftOf="parent"
244
+
245
+ app:layout_constraintRight_toRightOf="parent"
246
+
247
+ app:layout_constraintTop_toBottomOf="@id/btnOpenDialog" />
248
+
249
+
250
+
251
+ <TextView
252
+
253
+ android:id="@+id/tvData2"
254
+
255
+ android:layout_width="wrap_content"
256
+
257
+ android:layout_height="wrap_content"
258
+
259
+ android:text="TextView"
260
+
261
+ app:layout_constraintRight_toRightOf="parent"
262
+
263
+ app:layout_constraintLeft_toLeftOf="parent"
264
+
265
+ app:layout_constraintTop_toBottomOf="@id/tvData1"
266
+
267
+ app:layout_constraintBottom_toBottomOf="parent"
268
+
269
+ />
270
+
271
+ </androidx.constraintlayout.widget.ConstraintLayout>
272
+
273
+ ```
274
+
275
+
276
+
277
+ my_dialog.xml
278
+
279
+ ```
280
+
281
+ <?xml version="1.0" encoding="utf-8"?>
282
+
283
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
284
+
285
+ android:layout_width="match_parent"
286
+
287
+ android:layout_height="match_parent"
288
+
289
+ xmlns:app="http://schemas.android.com/apk/res-auto">
290
+
291
+
292
+
293
+ <EditText
294
+
295
+ android:id="@+id/etData1"
296
+
297
+ android:layout_width="wrap_content"
298
+
299
+ android:layout_height="wrap_content"
300
+
301
+ android:ems="10"
302
+
303
+ android:enabled="true"
304
+
305
+ android:inputType="textPersonName"
306
+
307
+ app:layout_constraintBottom_toTopOf="@+id/etData2"
308
+
309
+ app:layout_constraintLeft_toLeftOf="parent"
310
+
311
+ app:layout_constraintRight_toRightOf="parent"
312
+
313
+ app:layout_constraintTop_toTopOf="parent" />
314
+
315
+
316
+
317
+ <EditText
318
+
319
+ android:id="@+id/etData2"
320
+
321
+ android:layout_width="wrap_content"
322
+
323
+ android:layout_height="wrap_content"
324
+
325
+ android:ems="10"
326
+
327
+ android:enabled="true"
328
+
329
+ app:layout_constraintBottom_toBottomOf="parent"
330
+
331
+ app:layout_constraintLeft_toLeftOf="parent"
332
+
333
+ app:layout_constraintRight_toRightOf="parent"
334
+
335
+ app:layout_constraintTop_toBottomOf="@+id/etData1" />
336
+
337
+ </androidx.constraintlayout.widget.ConstraintLayout>
338
+
339
+ ```