回答編集履歴
2
コード修正
test
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
@Override
|
11
11
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
12
12
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.add_task_dialog, null);
|
13
|
-
|
13
|
+
|
14
14
|
EditText editText = view.findViewById(R.id.task_text);
|
15
|
-
CheckBox checkBox = view.findViewById(R.id.task_p
|
15
|
+
CheckBox checkBox = view.findViewById(R.id.task_important);
|
16
16
|
|
17
17
|
return new AlertDialog.Builder(getContext())
|
18
18
|
.setView(view) //ダイアログのレイアウトを適用
|
@@ -22,8 +22,8 @@
|
|
22
22
|
.create();
|
23
23
|
}
|
24
24
|
|
25
|
-
private void onPositive(String task_text, boolean task_p
|
25
|
+
private void onPositive(String task_text, boolean task_important) {
|
26
|
-
Log.d(TAG, "task_text="+task_text+", task_p
|
26
|
+
Log.d(TAG, "task_text="+task_text+", task_important="+task_important);
|
27
27
|
/*
|
28
28
|
//タスク追加処理
|
29
29
|
disposable.add(taskModel.insertTask(task_text)
|
@@ -54,7 +54,7 @@
|
|
54
54
|
android:layout_marginBottom="4dp" />
|
55
55
|
|
56
56
|
<CheckBox
|
57
|
-
android:id="@+id/task_p
|
57
|
+
android:id="@+id/task_important"
|
58
58
|
android:text="重要"
|
59
59
|
android:layout_width="wrap_content"
|
60
60
|
android:layout_height="wrap_content" />
|
1
コード追加
test
CHANGED
@@ -1,2 +1,63 @@
|
|
1
1
|
setView でカスタムレイアウトをコンテンツ領域に表示していますので、そのコンテンツ領域に表示するオプションは使えないのではないでしょうか。
|
2
2
|
チェックボックス1つ位なら単にカスタムレイアウトに追加してしまえば良いと思います。
|
3
|
+
|
4
|
+
AddTaskDialogFragment.java
|
5
|
+
```java
|
6
|
+
public class AddTaskDialogFragment extends DialogFragment {
|
7
|
+
private static final String TAG = "AddTaskDialogFragment";
|
8
|
+
|
9
|
+
@NonNull
|
10
|
+
@Override
|
11
|
+
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
12
|
+
View view = LayoutInflater.from(getContext()).inflate(R.layout.add_task_dialog, null);
|
13
|
+
|
14
|
+
EditText editText = view.findViewById(R.id.task_text);
|
15
|
+
CheckBox checkBox = view.findViewById(R.id.task_priority);
|
16
|
+
|
17
|
+
return new AlertDialog.Builder(getContext())
|
18
|
+
.setView(view) //ダイアログのレイアウトを適用
|
19
|
+
.setMessage("タスクの追加")
|
20
|
+
.setPositiveButton("OK", (dialog,id) -> onPositive(editText.getText().toString(), checkBox.isChecked()))
|
21
|
+
.setNegativeButton("キャンセル", (dialog,id) -> {})
|
22
|
+
.create();
|
23
|
+
}
|
24
|
+
|
25
|
+
private void onPositive(String task_text, boolean task_priority) {
|
26
|
+
Log.d(TAG, "task_text="+task_text+", task_priority="+task_priority);
|
27
|
+
/*
|
28
|
+
//タスク追加処理
|
29
|
+
disposable.add(taskModel.insertTask(task_text)
|
30
|
+
.subscribeOn(Schedulers.io())
|
31
|
+
.observeOn(AndroidSchedulers.mainThread())
|
32
|
+
.subscribe(() -> {}, throwable -> Log.e(TAG, "Unable to update username", throwable)));
|
33
|
+
*/
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
res/layout/add_task_dialog.xml
|
38
|
+
```xml
|
39
|
+
<?xml version="1.0" encoding="utf-8"?>
|
40
|
+
<LinearLayout
|
41
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
42
|
+
android:orientation="vertical"
|
43
|
+
android:layout_width="match_parent"
|
44
|
+
android:layout_height="match_parent">
|
45
|
+
|
46
|
+
<EditText
|
47
|
+
android:id="@+id/task_text"
|
48
|
+
android:inputType="text"
|
49
|
+
android:layout_width="match_parent"
|
50
|
+
android:layout_height="wrap_content"
|
51
|
+
android:layout_marginTop="16dp"
|
52
|
+
android:layout_marginLeft="4dp"
|
53
|
+
android:layout_marginRight="4dp"
|
54
|
+
android:layout_marginBottom="4dp" />
|
55
|
+
|
56
|
+
<CheckBox
|
57
|
+
android:id="@+id/task_priority"
|
58
|
+
android:text="重要"
|
59
|
+
android:layout_width="wrap_content"
|
60
|
+
android:layout_height="wrap_content" />
|
61
|
+
|
62
|
+
</LinearLayout>
|
63
|
+
```
|