質問編集履歴

1

新規に追加したクラスを追記しました。これでダイアログは表示できますが、内容に即さないものになります。

2021/07/09 03:04

投稿

tasojiro
tasojiro

スコア16

test CHANGED
File without changes
test CHANGED
@@ -98,13 +98,15 @@
98
98
 
99
99
  public void onItemClick(AdapterView<?> parent, View view, int position, long id){
100
100
 
101
- String item = (String)parent.getItemAtPosition(position);
101
+ //String item = (String)parent.getItemAtPosition(position);
102
102
 
103
103
 
104
104
 
105
105
  // ここにダイアログの表示をするコード?
106
106
 
107
-
107
+ OrderConfirmDialogFragment dialogFragment = new OrderConfirmDialogFragment();
108
+
109
+ dialogFragment.show(getSupportFragmentManager(), "OrderConfirmDialogFragment");
108
110
 
109
111
  }
110
112
 
@@ -116,6 +118,84 @@
116
118
 
117
119
 
118
120
 
121
+ 新規に追加したクラス
122
+
123
+ ```java
124
+
125
+ package com.websarva.wings.android.town_infoapp;
126
+
127
+
128
+
129
+ import android.app.AlertDialog;
130
+
131
+ import android.app.Dialog;
132
+
133
+ import android.content.DialogInterface;
134
+
135
+ import android.os.Bundle;
136
+
137
+
138
+
139
+ import androidx.fragment.app.DialogFragment;
140
+
141
+ import androidx.fragment.app.FragmentManager;
142
+
143
+
144
+
145
+ public class OrderConfirmDialogFragment extends DialogFragment {
146
+
147
+ @Override
148
+
149
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
150
+
151
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
152
+
153
+ builder.setTitle(R.string.dialog_title);
154
+
155
+ builder.setMessage(R.string.dialog_msg);
156
+
157
+ builder.setNegativeButton(R.string.dialog_bt_ng, new DialogButtonClickListener());
158
+
159
+ AlertDialog dialog = builder.create();
160
+
161
+ return dialog;
162
+
163
+ }
164
+
165
+
166
+
167
+ private class DialogButtonClickListener implements DialogInterface.OnClickListener {
168
+
169
+ @Override
170
+
171
+ public void onClick (DialogInterface dialog , int which){
172
+
173
+ String msg = "";
174
+
175
+ switch (which) {
176
+
177
+ case DialogInterface.BUTTON_NEGATIVE:
178
+
179
+ msg = getString(R.string.dialog_bt_ng);
180
+
181
+ break;
182
+
183
+ }
184
+
185
+ }
186
+
187
+ }
188
+
189
+ }
190
+
191
+
192
+
193
+ ```
194
+
195
+ onClick関数のmsgは使用していませんが、ダイアログの閉じるボタンを実装する際に必要な関数だったので記述しています。
196
+
197
+
198
+
119
199
  ### 試したこと
120
200
 
121
201