2012-02-07 5 views
0

サービスコール情報を含むsqliteテーブルからExpandableListViewを入力しています。私は親グループをそれぞれユニークなサービスサイトにし、子グループにそのサイトのすべてのコールのコール情報を格納したい。ExpandableListView親/子グループ化の問題

Site A 
    Call 1 
Site B 
    Call 2 

代わりに、私は取得しています:

Site A 
    Call 1 
    Call 2 
Site B 
    Call 1 
    Call 2 

すべてのサービスコールは、すべてのサイトの下に表示されます。私は今日間ExpandableListViewsで壁に頭を叩いてきたと私はそれを使用することができましたコードのみがちょうどクラッシュ様々なエラーやアプリの猛攻撃が発生していないこと

public class Today : ExpandableListActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     SetContentView(Resource.Layout.Boards); 

     List<IDictionary<string, object>> parent = new List<IDictionary<string,object>>(); 
     List<IList<IDictionary<string, object>>> child = new List<IList<IDictionary<string,object>>>(); 

     External inst = new External(); 
     var connection = inst.conn(); 
     var c = connection.CreateCommand(); 
     c.CommandText = "Select Distinct Store || ' ' || City || ', ' || State From Calls"; 
     connection.Open(); 
     SqliteDataReader dr = c.ExecuteReader(); 
     if (dr.HasRows) 
      while (dr.Read()) 
      { 
       Dictionary<string, object> pItem = new Dictionary<string,object>(); 
       pItem.Add("Store", dr[0].ToString()); 
       parent.Add(pItem); 
      } 
     dr.Close(); 
     int cnt = parent.Count(); 

     if (cnt > 0) 
     { 
      List<IDictionary<string, object>> children = new List<IDictionary<string, object>>(); 
      foreach(IDictionary<string, object> d in parent) 
      { 
       foreach (KeyValuePair<string, object> k in d) 
       { 
        var store = k.Value.ToString().Substring(0, k.Value.ToString().IndexOf(" ")); 
        c.CommandText = "Select CallNumber || ' ' || Description From Calls Where Store = '" + store + "'"; 
        dr = c.ExecuteReader(); 
        while (dr.Read()) 
        { 
         Dictionary<string, object> childItem = new Dictionary<string, object>(); 
         childItem.Add("Call", dr[0].ToString()); 
         children.Add(childItem); 
        } 
        dr.Close(); 
        child.Add(children); 
       } 

      }    
     } 
     ExpandableListView view = (ExpandableListView)FindViewById(Android.Resource.Id.List); 
     IExpandableListAdapter adapter = new SimpleExpandableListAdapter(this, parent, Android.Resource.Layout.SimpleExpandableListItem1, new string[] { "Store", "Call" }, new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 }, child, Android.Resource.Layout.SimpleExpandableListItem2, new string[] { "Store", "Call" }, new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 }); 
     view.SetAdapter(adapter); 
    } 

} 

答えて

1

ありますchildItemを同じList(子)に追加してから、このリストを子に複数回追加しています。

あなたはExpandableListView

+0

大漁上のすべてのグループのためのList<List<>>を作成する必要があります。ありがとう! – jmease