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

回答編集履歴

8

コード修正

2018/10/31 07:45

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -48,8 +48,8 @@
48
48
  }
49
49
  else
50
50
  {
51
- groupList = new List<IDictionary<string, object>>();
51
+ groupList = new JavaList<IDictionary<string, object>>();
52
- childList = new List<IList<IDictionary<string, object>>>();
52
+ childList = new JavaList<IList<IDictionary<string, object>>>();
53
53
 
54
54
  ...
55
55
  }

7

コード修正

2018/10/31 07:45

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -77,5 +77,5 @@
77
77
  outState.PutSerializable(nameof(groupList), groupList.JavaCast<ISerializable>());
78
78
  outState.PutSerializable(nameof(childList), childList.JavaCast<ISerializable>());
79
79
  }
80
- }
80
+ }
81
81
  ```

6

追記

2018/10/31 07:09

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -20,4 +20,62 @@
20
20
  });
21
21
  ```
22
22
 
23
- あと、ダイアログで入力した値を使うのであれば、この処理は、`SetPositiveButton`の`handler`内でやるべきです。
23
+ あと、ダイアログで入力した値を使うのであれば、この処理は、`SetPositiveButton`の`handler`内でやるべきです。
24
+
25
+ ---
26
+
27
+ リストデータの保存は、`OnSaveInstanceState`で`PutSerializable`で行い、`OnCreate`で、`GetSerializable`で取得します。
28
+
29
+ ```C#
30
+ public class MainActivity : Activity
31
+ {
32
+ private JavaList<IDictionary<string, object>> groupList;
33
+ private JavaList<IList<IDictionary<string, object>>> childList;
34
+
35
+ protected override void OnCreate(Bundle savedInstanceState)
36
+ {
37
+ base.OnCreate(savedInstanceState);
38
+
39
+ // Set our view from the "main" layout resource
40
+ SetContentView(Resource.Layout.Main);
41
+
42
+ ...
43
+
44
+ if (savedInstanceState != null)
45
+ {
46
+ groupList = savedInstanceState.GetSerializable(nameof(groupList)).JavaCast<JavaList<IDictionary<string, object>>>();
47
+ childList = savedInstanceState.GetSerializable(nameof(childList)).JavaCast<JavaList<IList<IDictionary<string, object>>>>();
48
+ }
49
+ else
50
+ {
51
+ groupList = new List<IDictionary<string, object>>();
52
+ childList = new List<IList<IDictionary<string, object>>>();
53
+
54
+ ...
55
+ }
56
+
57
+ SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
58
+ this,
59
+ groupList,
60
+ Android.Resource.Layout.SimpleExpandableListItem1,
61
+ new string[] { "GROUPE_TITLE" },
62
+ new int[] { Android.Resource.Id.Text1 },
63
+ childList,
64
+ Android.Resource.Layout.SimpleExpandableListItem2,
65
+ new string[] { "CHILD_TITLE" },
66
+ new int[] { Android.Resource.Id.Text2 }
67
+ );
68
+ memolist.SetAdapter(adapter);
69
+
70
+ ...
71
+ }
72
+
73
+ protected override void OnSaveInstanceState(Bundle outState)
74
+ {
75
+ base.OnSaveInstanceState(outState);
76
+
77
+ outState.PutSerializable(nameof(groupList), groupList.JavaCast<ISerializable>());
78
+ outState.PutSerializable(nameof(childList), childList.JavaCast<ISerializable>());
79
+ }
80
+ }
81
+ ```

5

コード修正

2018/10/31 07:08

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -9,7 +9,7 @@
9
9
  if (!string.IsNullOrEmpty(notename.Text))
10
10
  {
11
11
  var newGroupElement = new JavaDictionary<string, object>();
12
- newGroupElement.Add("GROUPE_LIST", notename.Text);
12
+ newGroupElement.Add("GROUPE_TITLE", notename.Text);
13
13
  groupList.Add(newGroupElement);
14
14
  adapter.NotifyDataSetChanged();
15
15
  }

4

コード修正

2018/10/31 02:51

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -6,7 +6,7 @@
6
6
  {
7
7
  Toast.MakeText(this, notename.Text, ToastLength.Short).Show();
8
8
 
9
- if (!string.IsNullOrEmpty(notename.Text)
9
+ if (!string.IsNullOrEmpty(notename.Text))
10
10
  {
11
11
  var newGroupElement = new JavaDictionary<string, object>();
12
12
  newGroupElement.Add("GROUPE_LIST", notename.Text);

3

コード修正

2018/10/29 02:44

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -4,12 +4,19 @@
4
4
  ```C#
5
5
  dlg.SetPositiveButton("OK", (s, a) =>
6
6
  {
7
- var newGroupElement = new JavaDictionary<string, object>();
8
- newGroupElement.Add("GROUPE_LIST", notename.Text);
9
- groupList.Add(newGroupElement);
10
- adapter.NotifyDataSetChanged();
11
-
12
7
  Toast.MakeText(this, notename.Text, ToastLength.Short).Show();
8
+
9
+ if (!string.IsNullOrEmpty(notename.Text)
10
+ {
11
+ var newGroupElement = new JavaDictionary<string, object>();
12
+ newGroupElement.Add("GROUPE_LIST", notename.Text);
13
+ groupList.Add(newGroupElement);
14
+ adapter.NotifyDataSetChanged();
15
+ }
16
+ else
17
+ {
18
+ // 未入力エラー
19
+ }
13
20
  });
14
21
  ```
15
22
 

2

コード修正

2018/10/29 02:44

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -9,7 +9,7 @@
9
9
  groupList.Add(newGroupElement);
10
10
  adapter.NotifyDataSetChanged();
11
11
 
12
- Toast.MakeText(this, notename.Text, ToastLength.Short).Show());
12
+ Toast.MakeText(this, notename.Text, ToastLength.Short).Show();
13
13
  });
14
14
  ```
15
15
 

1

コード修正

2018/10/29 02:41

投稿

f-miyu
f-miyu

スコア1625

answer CHANGED
@@ -2,10 +2,15 @@
2
2
  また、`groupList`に追加する`groupElement`は新しくオブジェクトを作成しなければいけません。
3
3
 
4
4
  ```C#
5
+ dlg.SetPositiveButton("OK", (s, a) =>
6
+ {
5
- var newGroupElement = new JavaDictionary<string, object>();
7
+ var newGroupElement = new JavaDictionary<string, object>();
6
- newGroupElement.Add("GROUPE_LIST", notename.Text);
8
+ newGroupElement.Add("GROUPE_LIST", notename.Text);
7
- groupList.Add(newGroupElement);
9
+ groupList.Add(newGroupElement);
8
- adapter.NotifyDataSetChanged();
10
+ adapter.NotifyDataSetChanged();
11
+
12
+ Toast.MakeText(this, notename.Text, ToastLength.Short).Show());
13
+ });
9
14
  ```
10
15
 
11
16
  あと、ダイアログで入力した値を使うのであれば、この処理は、`SetPositiveButton`の`handler`内でやるべきです。