求救,tabhost ListActivity怎么样合在一起。

aree 2013-04-08 09:59:47
想做一个tabhost分两页的界面。在每一页tab page中,放一个ListActivity.要求tab标签在界面的最下端。
tabmain.xml文件内容

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@+id/maintabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">

<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab1"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout>
</FrameLayout>
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"></TabWidget>
</RelativeLayout>
</TabHost>



tabmini.xml文件内容
<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:background="@drawable/icon">

<TextView android:id="@+id/tab_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold"
android:background="@drawable/icon"/>
</RelativeLayout>


Test1Activity.java文件名
package com.test.t1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class Test1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.tabmain);

TabHost tabHost = (TabHost) findViewById(R.id.maintabhost);
tabHost.setup();

//tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(R.id.tab1));
//tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(R.id.tab2));

Intent intent1 = new Intent(this, ListV.class);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(intent1));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(intent1));
}
}


ListV.java文件内容(使用了ListActivity)
package com.test.t1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

public class ListV extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getListView().setCacheColorHint(0);
this.getListView().setBackgroundColor(android.graphics.Color.WHITE);
SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.main,new String[]{"title","info"}, new int[]{1,2});
setListAdapter(adapter);
}

private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

Map<String, Object> map = new HashMap<String, Object>();


map = new HashMap<String, Object>();
map.put("title", "L1");
map.put("info", "1111111111111111111111111111");

list.add(map);

map = new HashMap<String, Object>();
map.put("title", "L2");
map.put("info", "22222222");

list.add(map);

return list;
}
}


从上面的Test1Actitity.java中

//tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(R.id.tab1)); //tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(R.id.tab2));
Intent intent1 = new Intent(this, ListV.class); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(intent1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(intent1));

使用R.id.tab1这个ListView组件来,是可以正常显示的。
但使用intent1(是一个ListActivity)则会报错。

哪位能告诉一下,应该怎么弄?
...全文
195 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aree 2013-04-09
  • 打赏
  • 举报
回复
太对了,ActivityGroup,刚试了,是OK。
豆豆虫豆豆 2013-04-08
  • 打赏
  • 举报
回复
引用 2 楼 busybeeCS 的回复:
引用 1 楼 justwandering 的回复:现在好像不怎么流行用tabhost了,fragement更流行一点, 那如何在3.0以下的版本中实现一样的效果呢?
不是有android-support-v4这种东西吗?
aree 2013-04-08
  • 打赏
  • 举报
回复
是啊。我的是兼容2.2.2的。 tabhost不能弄?
busybeeCS 2013-04-08
  • 打赏
  • 举报
回复
引用 1 楼 justwandering 的回复:
现在好像不怎么流行用tabhost了,fragement更流行一点,
那如何在3.0以下的版本中实现一样的效果呢?
豆豆虫豆豆 2013-04-08
  • 打赏
  • 举报
回复
现在好像不怎么流行用tabhost了,fragement更流行一点,
haoyizsw 2013-04-08
  • 打赏
  • 举报
回复
public class Test1 extends ActivityGroup试试

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧