Android学习--ListView和Tab
产生一个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的更多相关文章
- Android学习---ListView和Inflater的使用,将一个布局文件转化为一个对象
本文将介绍ListView和Inflater的使用,将接上一篇文章内容. 一.什么是ListView? 在android开发中ListView是比较常用的控件,ListView 控件可使用四种不同视图 ...
- android 学习 ListView使用补充
前面两篇学习适配器的时候用的就是listview,主要是简单的添加,今晚在看了下listview滚动状态事件和动态加载数据,一个小demo. listview的滚动状态主要有三种,onScrollSt ...
- Android学习--ListView
这篇文章用于总结自己这两天学到的安卓的ListView和RecyclerView 的笔记,以及从我这个iOS开发者的角度去理解和学习这两个控件,会比较一下他们个iOS中那些控件是一致的,可以用来对比的 ...
- Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用
如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...
- Android学习——ListView的缓存机制
在使用ListView的时候,需要加载适配器和数据源,这篇文章主要介绍一下ListView的使用以及利用ListView的缓存机制来减少系统的初始化时间. ListView的使用 ListView和V ...
- 42.Android之ListView中ArrayAdapter简单学习
今天学习下Android中ListView关于ArrayAdapter数据绑定, 废话少说直接上代码. 改下布局文件: <?xml version="1.0" encodin ...
- 38.Android之ListView简单学习(一)
android中ListView用的很普遍,今天来学习下,本篇主要以本地数据加载到listview,后面会学习从网络获取数据添加到listview. 首先改下布局文件: <?xml versio ...
- android学习笔记12——ListView、ListActivity
ListView.ListActivity ==> ListView以垂直列表的形式显示所有列表项. 创建ListView的方式: 1.直接使用ListView创建 2.Activity继承Li ...
- Android学习随笔--ListView的分页功能
第一次写博客,可能格式,排版什么的会非常不美观,不过我主要是为了记录自己的Android学习之路,为了以后能有些东西回顾.既然是为了学习,那我肯定会吸收各位大大们的知道经验,有不足的地方请指出. 通过 ...
- Android学习笔记(20)————利用ListView制作带竖线的多彩表格
http://blog.csdn.net/conowen/article/details/7421805 /********************************************** ...
随机推荐
- HarmonyOS 4.0 实况窗上线!支付宝实现医疗场景智能提醒
本文转载自支付宝体验科技,作者是蚂蚁集团客户端工程师博欢,介绍了支付宝如何基于 HarmonyOS 4.0 实况窗实现医疗场景履约智能提醒. 1.话题背景 8 月 4 日,华为在 HDC(华为 202 ...
- Vue2系列(lqz)——slot插槽 (内容分发)、2 transition过渡、3 生命周期、4 swiper学习、5 自定义组件的封装、6 自定义指令、7 过滤器
文章目录 1 slot插槽 (内容分发) 1.1 基本使用 1.2 插槽应用场景1 1.3 插槽应用场景2 1.4 具名插槽 2 transition过渡 3 生命周期 4 swiper学习 5 自定 ...
- HexConversion 二进制 八进制 十六进制 十进制
public class HexConversion { // TODO Auto-generated method stub /** * TODO 进制转换. * * @param cc * htt ...
- 铅华洗尽,粉黛不施,人工智能AI基于ProPainter技术去除图片以及视频水印(Python3.10)
视频以及图片修复技术是一项具有挑战性的AI视觉任务,它涉及在视频或者图片序列中填补缺失或损坏的区域,同时保持空间和时间的连贯性.该技术在视频补全.对象移除.视频恢复等领域有广泛应用.近年来,两种突出的 ...
- Lucky Array 题解
Lucky Array 题目大意 维护一个序列,支持以下操作: 区间加一个大于 \(0\) 的数. 区间查询有多少个数位上只包含 \(4\) 或 \(7\) 的数. 思路分析 看起来很不可做,但考虑到 ...
- STL 迭代器
工作之余看了一下<<accelerated c++>>这本书,挺有意思没,没有一大堆概念,直接就开始一步一步编写代码. 书中时不时会涉及到一些stl的概念,比如容器,算法,迭代 ...
- 飞码LowCode前端技术系列(二):如何便捷配置出页面 | 京东云技术团队
一.配置解法 飞码LowCode前端技术(一)中飞码提出了至少需要满足2个大能力点以及对应16个细化点.在业务复杂的场景下数据具有流转性质,事件的触发会改变数据.同时也会触发其他事件等情况.飞码使用数 ...
- 这次弄一下maven 多模块项目,用vscode新建一下,便于管理项目
首先 创建一个mvn项目, 直接在命令行执行, 原型生成: mvn archetype:generate 选一个maven quick start的template, 然后删除src和target文件 ...
- 在VM虚拟机中安装FTP服务
自用的话,建议先关掉防火墙 systemctl stop firewalld #关闭防火墙 systemctl disable firewalld.service #设置开机禁用防火墙 systemc ...
- Redis 技术整理
认识Redis Redis官网:https://redis.io/ Redis诞生于2009年全称是Remote Dictionary Server 远程词典服务器,是一个基于内存的键值型NoSQL数 ...