ANDROID_MARS学习笔记_S01原始版_022_MP3PLAYER002_本地及remote标签
一、简介
1.在main.xml中用TabHost、TabWidget、FrameLayout标签作布局
2.在MainActivity中生成TabHost、TabSpec,调用setIndicator()、setContent()、addTab(),用Intent指明要跳转的tab对应的class
3.在onResume中写获取本地mp3信息的代码,代码在onResume中,则切换tab时,mp3信息每次都会更新
二、代码
1.xml
(1)main.xml
<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:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
(2)AndroidManifest.xml
增加activity
<activity android:name=".LocalMp3ListActivity" android:label="@string/app_name"/>
<activity android:name=".Mp3ListActivity" android:label="@string/app_name"/>
2.java
(1)MainActivity.java
package tony.mp3player; import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost; public class MainActivity extends TabActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//得到TabHost对象,对TabActivity的操作通常都有这个对象完成
TabHost tabHost = getTabHost();
//生成一个Intent对象,该对象指向一个Activity
Intent remoteIntent = new Intent();
remoteIntent.setClass(this, Mp3ListActivity.class);
//生成一个TabSpec对象,这个对象代表了一个页
TabHost.TabSpec remoteSpec = tabHost.newTabSpec("Remote");
Resources res = getResources();
//设置该页的indicator
remoteSpec.setIndicator("Remote", res.getDrawable(android.R.drawable.stat_sys_download));
//设置该页的内容
remoteSpec.setContent(remoteIntent);
//将设置好的TabSpec对象添加到TabHost当中
tabHost.addTab(remoteSpec); Intent localIntent = new Intent();
localIntent.setClass(this, LocalMp3ListActivity.class);
TabHost.TabSpec localSpec = tabHost.newTabSpec("Local");
localSpec.setIndicator("Local", res.getDrawable(android.R.drawable.stat_sys_upload));
localSpec.setContent(localIntent);
tabHost.addTab(localSpec);
}
}
(2)FileUtils.java增加函数
public List<Mp3Info> getMp3Infos(String path) {
List<Mp3Info> list = new ArrayList<Mp3Info>();
File file = new File(SDCardRoot + File.separator + path);
File[] files = file.listFiles();
for(File tempFile : files) {
if(tempFile.getName().endsWith(".mp3")) {
list.add(new Mp3Info(tempFile.getName(), tempFile.length()+""));
}
}
return list;
}
ANDROID_MARS学习笔记_S01原始版_022_MP3PLAYER002_本地及remote标签的更多相关文章
- ANDROID_MARS学习笔记_S01原始版_005_RadioGroup\CheckBox\Toast
一.代码 1.xml(1)radio.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- ANDROID_MARS学习笔记_S01原始版_004_TableLayout
1.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android ...
- ANDROID_MARS学习笔记_S01原始版_003_对话框
1.AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest ...
- ANDROID_MARS学习笔记_S01原始版_002_实现计算乘积及menu应用
一.代码 1.xml(1)activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...
- ANDROID_MARS学习笔记_S01原始版_001_Intent
一.Intent简介 二.代码 1.activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.co ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER005_用广播BroacastReciever实现后台播放不更新歌词
一.代码流程1.自定义一个AppConstant.LRC_MESSAGE_ACTION字符串表示广播"更新歌词" 2.在PlayerActivity的onResume()注册Bro ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER004_同步显示歌词
一.流程分析 1.点击播放按钮,会根据lrc名调用LrcProcessor的process()分析歌词文件,得到时间队列和歌词队列 2.new一个hander,把时间队列和歌词队列传给自定义的线程类U ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER003_播放mp3
一.简介 1.在onListItemClick中实现点击条目时,跳转到PlayerActivity,mp3info通过Intent传给PlayerActivity 2.PlayerActivity通过 ...
- ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件
一.简介 1.在onListItemClick()中new Intent,Intent以存储序列化后的mp2Info对象作为参数,启动serivce 2.DownloadService在onStart ...
随机推荐
- ASP生成静态文件编码为UTF-8格式的HTML文件
一般在ASP环境下,运行动生静操作时都用到的是FSO,FSO是专门对文件进行操作的一个组件,FSO的编码属性只有三种,系统默认,Unicode,ASCII,并没有utf-8,所以一般中文系统上使用FS ...
- 第五篇、常用的SQL语句和函数介绍
简介: 在使用到sqlite3的时候,常常需要写一些SQL语句,现将常用到的部分语句稍微总结以下,由于个人习惯,关键字用大写. 附: /*简单约束*/ CREATE TABLE IF NOT EXIS ...
- .Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法
阐述签名工具这个概念之前,我先说说它不是什么: 1.它不是用于给程序集加密的工具,它与阻止Reflector或ILSpy对程序集进行反编译一毛钱关系都没有. 2.它很讨厌人们把它和加密联系在一起. 我 ...
- 手把手教你写电商爬虫-第三课 实战尚妆网AJAX请求处理和内容提取
版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 看完两篇,相信大家已经从开始的 ...
- web前端面试题收集(一)
CSS中margin和padding的区别? Javascript中如何检测一个变量是一个String类型?请写出函数实现. 网页中实现一个计算当年还剩多少时间的倒计时程序,要求网页上实时动态显示“x ...
- WIX: Hide installed program from the Add/Remove Programs window.
Reference article : How to hide an entry in the Add/Remove Programs applet? In Wix source files, set ...
- 在Mac OS X中搭建STM32开发环境(1)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 本文方法必须好用!绝不坑爹!看了N多英文资料才搞明白的,适用于STM32F4DISCOVERY评估板,带 ...
- Chrome 将默认不播放非重要 Flash 内容
Chrome 45将不再自动播放Flash,可能是45以后的版本都不自动播放了,没有具体测试. 小尺寸flash不被chrome播放,需要手动点击才能播放如何解决: <p>1.同域名fla ...
- 网页clientWidth等相关
javascript代码: function getInfo() { var s = ""; s += & ...
- 聊天工具实现winform端实现
最近在找能够实现客户端点对点聊天的技术,通过github我发现了一个项目,它能够支持webscoket通讯,服务端是由c#socket完成. 我要的是winform端的通信,所以在他的基础上,增加了桌 ...