产生一个ListView 其中包含很多items,第一个item启动另一个实现了Tab的Activity。

关于tab的使用方式,参见下面blog

http://oldshark.blog.163.com/blog/static/97167342011729112640919/

http://erbo2008.iteye.com/blog/1542733

源码框架如下:

MainActivity.java:

 1 package com.example.listviewdemo;
2
3 import android.os.Bundle;
4 import android.app.Activity;
5 import android.app.ListActivity;
6 import android.content.Intent;
7 import android.view.Menu;
8 import android.view.View;
9 import android.widget.AdapterView.OnItemClickListener;
10 import android.widget.ArrayAdapter;
11 import android.widget.ListAdapter;
12 import android.widget.ListView;
13 import android.widget.TextView;
14 import android.widget.Toast;
15
16 public class MainActivity extends ListActivity {
17 private TextView textView;
18 private String[] items = {"item1","item2","item3","item4","item5","item6"};
19 @Override
20 protected void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 setContentView(R.layout.activity_main);
23 textView = (TextView) findViewById(R.id.TextView);
24 setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
25 items));
26 }
27
28 @Override
29 protected void onListItemClick(ListView l, View v, int position, long id) {
30 // TODO Auto-generated method stub
31 super.onListItemClick(l, v, position, id);
32
33 textView.setText(items[position]);
34 Toast.makeText(this, position+"", Toast.LENGTH_LONG).show();
35 switch (position) {
36 case 0:
37 Intent intent = new Intent();
38 intent.setClass(this, TabDemo.class);
39 startActivity(intent);
40 break;
41
42 default:
43 break;
44 }
45
46 }
47
48 @Override
49 public boolean onCreateOptionsMenu(Menu menu) {
50 // Inflate the menu; this adds items to the action bar if it is present.
51 getMenuInflater().inflate(R.menu.main, menu);
52 return true;
53 }
54
55 }

TabDemo.java:

package com.example.listviewdemo;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost; public class TabDemo extends TabActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState); TabHost tabHost = getTabHost();
// LayoutInflater.from(this).inflate(R.layout.tab1,
// tabHost.getTabContentView(),true); LayoutInflater.from(this).inflate(R.layout.tab2,
tabHost.getTabContentView(),true);
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("布局1")
.setContent(new Intent(this,Tab1.class)));
tabHost.addTab(tabHost.newTabSpec("TAB2").setIndicator("布局2")
.setContent(R.id.tab2));
}
}

tab1.java

package com.example.listviewdemo;

import android.app.Activity;
import android.os.Bundle; public class Tab1 extends Activity{ @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
}
}

mainActivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<!-- **********NOTICE********** -->
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:layout_below="@id/TextView"
> </ListView> </RelativeLayout>

Tab1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/app_name"/> </LinearLayout>

Tab2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab2"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello_world"/>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.listviewdemo"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.listviewdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.listviewdemo.TabDemo"></activity>
<activity android:name="com.example.listviewdemo.Tab1"></activity>
</application> </manifest>

Android学习--ListView和Tab的更多相关文章

  1. Android学习---ListView和Inflater的使用,将一个布局文件转化为一个对象

    本文将介绍ListView和Inflater的使用,将接上一篇文章内容. 一.什么是ListView? 在android开发中ListView是比较常用的控件,ListView 控件可使用四种不同视图 ...

  2. android 学习 ListView使用补充

    前面两篇学习适配器的时候用的就是listview,主要是简单的添加,今晚在看了下listview滚动状态事件和动态加载数据,一个小demo. listview的滚动状态主要有三种,onScrollSt ...

  3. Android学习--ListView

    这篇文章用于总结自己这两天学到的安卓的ListView和RecyclerView 的笔记,以及从我这个iOS开发者的角度去理解和学习这两个控件,会比较一下他们个iOS中那些控件是一致的,可以用来对比的 ...

  4. Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用

    如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...

  5. Android学习——ListView的缓存机制

    在使用ListView的时候,需要加载适配器和数据源,这篇文章主要介绍一下ListView的使用以及利用ListView的缓存机制来减少系统的初始化时间. ListView的使用 ListView和V ...

  6. 42.Android之ListView中ArrayAdapter简单学习

    今天学习下Android中ListView关于ArrayAdapter数据绑定, 废话少说直接上代码. 改下布局文件: <?xml version="1.0" encodin ...

  7. 38.Android之ListView简单学习(一)

    android中ListView用的很普遍,今天来学习下,本篇主要以本地数据加载到listview,后面会学习从网络获取数据添加到listview. 首先改下布局文件: <?xml versio ...

  8. android学习笔记12——ListView、ListActivity

    ListView.ListActivity ==> ListView以垂直列表的形式显示所有列表项. 创建ListView的方式: 1.直接使用ListView创建 2.Activity继承Li ...

  9. Android学习随笔--ListView的分页功能

    第一次写博客,可能格式,排版什么的会非常不美观,不过我主要是为了记录自己的Android学习之路,为了以后能有些东西回顾.既然是为了学习,那我肯定会吸收各位大大们的知道经验,有不足的地方请指出. 通过 ...

  10. Android学习笔记(20)————利用ListView制作带竖线的多彩表格

    http://blog.csdn.net/conowen/article/details/7421805 /********************************************** ...

随机推荐

  1. JAVA实现单链表修改和删除数据节点

    JAVA实现单链表修改和删除数据节点 一.修改单链表中的一个节点 ①实现思路 因为带头节点的链表中头节点的next域不能发生改变(始终指向单链表的头节点),否则将找不到该链表.所以我们需要先找一个辅助 ...

  2. C++高精度算法

    文章结尾有惊喜 在 C++ 中,unsigned long long最大只能表示到2^64-1=18446744073709551615264−1=18446744073709551615 而有些题目 ...

  3. Django框架项目之上线——docker、部署上线

    文章目录 Docker CentOS安装Docker 设置管理Docker的仓库 安装Docker Engine-Community Docker基础命令 开启关闭 镜像操作 容器操作 Docker安 ...

  4. 【京东开源项目】微前端框架MicroApp 1.0正式发布

    介绍 MicroApp是由京东前端团队推出的一款微前端框架,它从组件化的思维,基于类WebComponent进行微前端的渲染,旨在降低上手难度.提升工作效率.MicroApp无关技术栈,也不和业务绑定 ...

  5. DevOps2023现状报告|注重文化、以用户为中心是成功的关键

    Google Cloud DORA 团队的一份新研究报告强调了企业文化和关注用户作为成功软件交付支柱的重要性. 2023 DevOps 状况报告分析了过去 9 年来通过此类最大规模调查收集的全球 36 ...

  6. 使用fontforge进行字体拆分

    fontforge官方网站 游戏开发为了节省内存和资源下载量,需要把字体不用的字删掉,或者拆成多个字体逐级加载,批量操作用UI就比较难搞了,用fontforge搞起来比较顺手 安装fontforge后 ...

  7. 后缀自动机 (SAM) 的构造及应用

    cnblogs 怎么又炸了. 为什么又可爱又强的 xxn 去年 9 月就会的科技樱雪喵现在还不会呢 /kel. 感觉 SAM 的教程已经被前人写烂了啊.那就写点个人学习过程中对 SAM 的理解. 参考 ...

  8. Chromium VIZ工作流

    在 Chromium 中 viz 的核心逻辑运行在 GPU 进程中,负责接收其他进程产生的 viz::CompositorFrame(简称 CF),然后把这些 CF 进行合成,并将合成的结果最终渲染在 ...

  9. Meissel–Lehmer 算法

    前言 推荐先行阅读我的blog文章----Min_25 筛 什么是Meissel–Lehmer 算法 Meissel-Lehmer 算法是一种基于 \(ϕ\) 函数的的快速计算前缀质数个数(当然也可以 ...

  10. Educational Codeforces Round 118 (Rated for Div. 2) D. MEX Sequences

    \(DP\)真的太难了啊!! 首先考虑到\(f(i, s)\)表示,从前\(i\)个数中选,最后一个数为\(a_i\),且\(MEX(a_1,....,a_i) = \left\{ \begin{al ...