2012-02-06 6 views
0
public class Boards : TabActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     SetContentView(Resource.Layout.Tab); 

     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent(this, typeof(Today)); 
     intent.AddFlags(ActivityFlags.NewTask); 

     spec = TabHost.NewTabSpec("today"); 
     spec.SetIndicator("Today"); 
     spec.SetContent(intent); 
     TabHost.AddTab(spec); 

     intent = new Intent(this, typeof(Tomorrow)); 
     intent.AddFlags(ActivityFlags.NewTask); 

     spec = TabHost.NewTabSpec("tomorrow"); 
     spec.SetIndicator("Tomorrow"); 
     spec.SetContent(intent); 
     TabHost.AddTab(spec); 

     TabHost.CurrentTab = 1; 
    } 
} 

Tab.axmlExpandableListView에서 TabHost

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"></TabWidget> 
     <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"></FrameLayout> 
    </LinearLayout> 
</TabHost> 

Today.cs이

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

     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 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) 
      { 
       c.CommandText = "Select CallNumber From Calls Where Store = '" + d.Values + "'"; 
       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); 
     } 

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

} 

이 탭은 잘 만들 추가하지만, 아무것도 보여줍니다 ExpandableListViewActivity를 데리고 오늘 탭을 클릭하면 쪽으로. Tab.axml의 LinearLayout을 Relative로 변경 한 다음 ExpandableListView가 나타나지만 첫 번째 항목이 오늘 탭 상단에 있고 항목을 확장하려고 시도하면 앱이 다운됩니다.

앱 Tab.axml가 RelativeLayout의 enter image description here

답변

0

가 작동 할 때 가지고있는 LinearLayout Tab.axml는

enter image description here

애플리케이션을 가질 때. 해결 방법은 상대적 레이아웃을 사용하여 Tab.axml을 그대로두고 FrameLayout을 TabWidget 아래에 지정하는 것입니다.

<FrameLayout 
android:id="@android:id/tabcontent" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_below="@android:id/tabs"> 
</FrameLayout>