添加在TabHost ExpandableListView [英] Add ExpandableListView Under TabHost

查看:92
本文介绍了添加在TabHost ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.axml

Tab.axml

<?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

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上,什么也不显示。我改变了的LinearLayout在Tab.axml为相对,然后ExpandableListView显示出来,但第一项是对当今标签之上,并试图展开项目崩溃的应用程序。

The tabs create just fine but if I click on the Today tab bringing up the ExpandableListViewActivity, nothing shows up. I changed the LinearLayout in the Tab.axml to Relative and then the ExpandableListView shows up but the first item is on top of the today tab and attempting to expand the item crashes the app.

应用程序时Tab.axml拥有的LinearLayout

App when Tab.axml has LinearLayout

应用程序时Tab.axml拥有的RelativeLayout

App when Tab.axml has RelativeLayout

推荐答案

得到它的工作。解决的办法是离开Tab.axml具有相对布局并指定的FrameLayout是TabWidget以下

Got it working. The solution is to leave the Tab.axml with a relative layout and specify the FrameLayout is below the TabWidget.

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

这篇关于添加在TabHost ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆