teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

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

2021/10/24 04:14

投稿

rasum
rasum

スコア21

title CHANGED
File without changes
body CHANGED
@@ -61,4 +61,110 @@
61
61
  2021-10-24 11:39:50.798 11288-11288/PACKAGE D/MyApp: Dialog: onStart
62
62
  2021-10-24 11:39:53.470 11288-11288/PACKAGE D/MyApp: Dialog: onStart
63
63
  2021-10-24 11:39:55.847 11288-11288/PACKAGE D/MyApp: Dialog: onStart
64
+ ```
65
+
66
+ MainActivity
67
+ ```
68
+ import androidx.appcompat.app.AppCompatActivity
69
+ import android.os.Bundle
70
+ import net.sytes.rokkosan.myalertdialog.databinding.ActivityMainBinding
71
+
72
+ class MainActivity : AppCompatActivity() {
73
+
74
+ private lateinit var viewBinding: ActivityMainBinding
75
+ val myDialogFragment = MyDialogFragment()
76
+
77
+ override fun onCreate(savedInstanceState: Bundle?) {
78
+ super.onCreate(savedInstanceState)
79
+ setContentView(R.layout.activity_main)
80
+
81
+ // set View Binding
82
+ viewBinding = ActivityMainBinding.inflate(layoutInflater)
83
+ setContentView(viewBinding.root)
84
+
85
+ viewBinding.btnOpenDialog.setOnClickListener {
86
+ myDialogFragment.show(supportFragmentManager, "my")
87
+
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ activity_main.xml
94
+ ```
95
+ <?xml version="1.0" encoding="utf-8"?>
96
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
97
+ xmlns:app="http://schemas.android.com/apk/res-auto"
98
+ xmlns:tools="http://schemas.android.com/tools"
99
+ android:layout_width="match_parent"
100
+ android:layout_height="match_parent"
101
+ tools:context=".MainActivity">
102
+
103
+ <Button
104
+ android:id="@+id/btnOpenDialog"
105
+ android:layout_width="wrap_content"
106
+ android:layout_height="wrap_content"
107
+ android:text="@string/btn_open_dialog"
108
+ android:visibility="visible"
109
+ app:layout_constraintBottom_toBottomOf="parent"
110
+ app:layout_constraintLeft_toLeftOf="parent"
111
+ app:layout_constraintRight_toRightOf="parent"
112
+ app:layout_constraintTop_toTopOf="parent"
113
+ tools:visibility="visible" />
114
+
115
+ <TextView
116
+ android:id="@+id/tvData1"
117
+ android:layout_width="wrap_content"
118
+ android:layout_height="wrap_content"
119
+ android:text="TextView"
120
+ app:layout_constraintBottom_toTopOf="@id/tvData2"
121
+ app:layout_constraintHorizontal_bias="0.501"
122
+ app:layout_constraintLeft_toLeftOf="parent"
123
+ app:layout_constraintRight_toRightOf="parent"
124
+ app:layout_constraintTop_toBottomOf="@id/btnOpenDialog" />
125
+
126
+ <TextView
127
+ android:id="@+id/tvData2"
128
+ android:layout_width="wrap_content"
129
+ android:layout_height="wrap_content"
130
+ android:text="TextView"
131
+ app:layout_constraintRight_toRightOf="parent"
132
+ app:layout_constraintLeft_toLeftOf="parent"
133
+ app:layout_constraintTop_toBottomOf="@id/tvData1"
134
+ app:layout_constraintBottom_toBottomOf="parent"
135
+ />
136
+ </androidx.constraintlayout.widget.ConstraintLayout>
137
+ ```
138
+
139
+ my_dialog.xml
140
+ ```
141
+ <?xml version="1.0" encoding="utf-8"?>
142
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
143
+ android:layout_width="match_parent"
144
+ android:layout_height="match_parent"
145
+ xmlns:app="http://schemas.android.com/apk/res-auto">
146
+
147
+ <EditText
148
+ android:id="@+id/etData1"
149
+ android:layout_width="wrap_content"
150
+ android:layout_height="wrap_content"
151
+ android:ems="10"
152
+ android:enabled="true"
153
+ android:inputType="textPersonName"
154
+ app:layout_constraintBottom_toTopOf="@+id/etData2"
155
+ app:layout_constraintLeft_toLeftOf="parent"
156
+ app:layout_constraintRight_toRightOf="parent"
157
+ app:layout_constraintTop_toTopOf="parent" />
158
+
159
+ <EditText
160
+ android:id="@+id/etData2"
161
+ android:layout_width="wrap_content"
162
+ android:layout_height="wrap_content"
163
+ android:ems="10"
164
+ android:enabled="true"
165
+ app:layout_constraintBottom_toBottomOf="parent"
166
+ app:layout_constraintLeft_toLeftOf="parent"
167
+ app:layout_constraintRight_toRightOf="parent"
168
+ app:layout_constraintTop_toBottomOf="@+id/etData1" />
169
+ </androidx.constraintlayout.widget.ConstraintLayout>
64
170
  ```