質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

Q&A

解決済

1回答

472閲覧

Xamarin.Android - ExpandableListViewのアダプターセットの仕方

sezaki_H

総合スコア41

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

0グッド

0クリップ

投稿2018/08/20 02:46

XamarinでExpandableListViewを使用しているのですが、アダプターセットの仕方が分からず困っています。
SimpleExpandableListAdapterの部分で
SimpleExpandableListAdapterには引数7を指定するコンストラクタは含まれていませんと表示されます。

c#

1SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( 2 this, 3 groupList, 4 Android.Resource.Layout.SimpleExpandableListItem1, 5 new string[] { "GROUPE_LIST" }, 6 childList, 7 Android.Resource.Layout.SimpleExpandableListItem2, 8 new string[] { "CHILD_TITLE" } 9 ); 10mlist.Adapter(adapter);

以下がリストのコードです。

c#

1 //親リストgroupList子リストchildList 2 List<Dictionary<string, string>> groupList = new List<Dictionary<string, string>>(); 3 List<List<Dictionary<string, object>>> childList = new List<List<Dictionary<string, object>>>(); 4 5 //デフォルトのグループ"全て" 6 Dictionary<string, string> groupElement = new Dictionary<string, string>(); 7 groupElement.Add("GROUP_TITLE", "全て"); 8 groupList.Add(groupElement); 9 10 11 12 13 14 //子リスト用の文字列(ファイル名)を配列に用意 15 n = 0; 16 foreach (var file in files) 17 { 18 var fn = file.Name; 19 fn = fn.Remove(fn.Length - 4);//拡張子を表示しないように末尾を削除 20 filename[n] = fn;//配列にファイル名を格納 21 n++; 22 } 23 24 25 List<Dictionary<string, object>> childElements = new List<Dictionary<string, object>>(); 26 for (int j = 0; j <= n; j++) 27 { 28 Dictionary<string, object> child = new Dictionary<string, object>(); 29 child.Add("CHILD_TITLE", filename[j]); 30 childElements.Add(child); 31 } 32 childList.Add(childElements);

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

groupTochildToの指定がありません。また、groupListchildListのキャストも必要です。

C#

1SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( 2 this, 3 (IList<IDictionary<string, object>>)groupList, 4 Android.Resource.Layout.SimpleExpandableListItem1, 5 new string[] { "GROUPE_LIST" }, 6 new int[] { Android.Resource.Id.Text1 }, 7 (IList<IList<IDictionary<string, object>>>)childList, 8 Android.Resource.Layout.SimpleExpandableListItem2, 9 new string[] { "CHILD_TITLE" }, 10 new int[] { Android.Resource.Id.Text2 } 11 );

groupListの型もList<Dictionary<string, object>>にしてください。
キャストしないで済むように、groupList、childListの型を最初から、List<IDictionary<string, object>>List<IList<IDictionay<string,object>>>にしておくのもありです。(こちらの方がいいかもです)

C#

1List<IDictionary<string,object>> groupList = new List<IDictionary<string,object>>(); 2List<IList<IDictionary<string, object>>> childList = new List<IList<IDictionary<string, object>>>();

追記

普通のListDictionayでは、ダメっぽいですね。
JavaListJavaDictionaryを使わないといけないようです。

C#

1 //親リストgroupList子リストchildList 2 List<IDictionary<string,object>> groupList = new List<IDictionary<string,object>>(); 3 List<IList<IDictionary<string, object>>> childList = new List<IList<IDictionary<string, object>>>(); 4 5 //デフォルトのグループ"全て" 6 JavaDictionary<string,object> groupElement = new JavaDictionary<string,object>(); 7 groupElement.Add("GROUP_TITLE", "全て"); 8 groupList.Add(groupElement); 9 10 11 12 13 14 //子リスト用の文字列(ファイル名)を配列に用意 15 n = 0; 16 foreach (var file in files) 17 { 18 var fn = file.Name; 19 fn = fn.Remove(fn.Length - 4);//拡張子を表示しないように末尾を削除 20 filename[n] = fn;//配列にファイル名を格納 21 n++; 22 } 23 24 25 JavaList<IDictionary<string, object>> childElements = new JavaList<IDictionary<string, object>>(); 26 for (int j = 0; j <= n; j++) 27 { 28 JavaDictionary<string, object> child = new JavaDictionary<string, object>(); 29 child.Add("CHILD_TITLE", filename[j]); 30 childElements.Add(child); 31 } 32 childList.Add(childElements); 33 34 SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( 35 this, 36 groupList, 37 Android.Resource.Layout.SimpleExpandableListItem1, 38 new string[] { "GROUPE_LIST" }, 39 new int[] { Android.Resource.Id.Text1 }, 40 childList, 41 Android.Resource.Layout.SimpleExpandableListItem2, 42 new string[] { "CHILD_TITLE" }, 43 new int[] { Android.Resource.Id.Text2 } 44 ); 45 expandableListView.SetAdapter(adapter);

投稿2018/08/20 03:25

編集2018/08/22 01:35
f-miyu

総合スコア1625

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sezaki_H

2018/08/22 00:50 編集

ありがとうございます! 構文エラーはなくなったのですが、実行するとキャストエラーが出てしまいます... Java.Lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map
f-miyu

2018/08/22 01:36

追記しました。実際に試したのでこれで大丈夫だと思います。
sezaki_H

2018/08/22 02:25

わざわざありがとうございます!! お聞きしたいことが次から次へと出てきてしまって申し訳ないのですが、内容ごとに質問を分けようと思うのでお時間ありましたら回答お願いします<m(__)m>
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問