求救,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)则会报错。

哪位能告诉一下,应该怎么弄?
...全文
273 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试试
打开链接下载源码: https://pan.quark.cn/s/d85aa9a28238 FreeRTOS,其全称为“Free Real-Time Operating System”,是一款具备开源特质且设计轻巧的实时操作系统(RTOS),主要应用于嵌入式系统领域。该“freertos工程文件以及官方文档.rar”压缩包内含了与FreeRTOS关联的工程文件、官方文档资料以及其他用于移植的文件,是进行FreeRTOS学习与应用的关键性资源。 FreeRTOS的核心特质涵盖任务调度机制、中断处理功能、同步机制设计以及内存管理策略。其中,任务调度机制是其核心功能,借助优先级抢占式调度算法,保障高优先级任务能够获得及时响应。中断处理功能是嵌入式系统中的关键环节,FreeRTOS支持在中断执行环境中开展特定操作,同时确保任务执行状态的安全。同步机制例如信号量、互斥量及事件标志组,主要用于实现任务之间的通信与协调。内存管理部分则负责动态分配和释放内存资源,以满足不同任务的特定需求。 工程文件通常由源代码、配置文件、编译脚本等构成,能够帮助开发者深入理解FreeRTOS的工作原理,并在此基础上进行定制化开发。例如,`FreeRTOSConfig.h`作为FreeRTOS的核心配置文件,允许用户依据目标硬件条件和应用需求调整内核参数,比如任务数量、堆大小等。 官方文档资料是学习FreeRTOS的重要参考资料,其内容详尽地阐述了系统架构、API函数、应用示例等关键信息。通过研读这些文档,开发者可以掌握如何创建任务、配置中断、实现任务间的同步与通信,以及如何对FreeRTOS系统进行调试和优化。 移植文件主要涉及将FreeRTOS部署于不同的微控制器(MCU)或硬件平台之上。每个平...

80,490

社区成员

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

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