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 ...
随机推荐
- Delphi - 在ListView中添加一个进度条
// 相关定义 Type TListData = Record FileName: String; Percent: Integer; End; PListData = ^TListData; // ...
- nopCommerce添加支付插件
之前完成了nopCommerce和汉化以及配置,今天继续对nopCommerce的研究,为了能够完成购物,我们就要将伟大的支付宝添加至其中了.支付宝插件下载 将Nop.Plugin.Payments. ...
- Sql Server Profiler保存与重演跟踪
重演跟踪的作用 可以将一个跟踪当做测试工具,当按照正确的顺序调用某些存储过程是肯能会重新生成特定的故障. 跟踪模板
- iOS创建UUID
- (NSString *)getUUID { CFUUIDRef uuidObj = CFUUIDCreate(nil); //create a new UUID NSString * uuidSt ...
- 【开发】Dialog 对话框
提示:Dialog 继承自 Panel,有大量的方法在 Panel 中已被定义,可以复用. Dialog API:http://www.jeasyui.net/plugins/181.html Pan ...
- 一种c#深拷贝方式完胜java深拷贝(实现上的对比)
楼主是一名asp.net攻城狮,最近经常跑java组客串帮忙开发,所以最近对java的一些基础知识特别上心.却遇到需要将一个对象深拷贝出来做其他事情,而原对象保持原有状态的情况.(实在是不想自己new ...
- EL表达式 入门
为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. JSP EL语言定义 E L(Expression L ...
- HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...
- iOS中数据库运用之前的准备-简单的数据库
1.数据持久化 数据持久化是通过文件将数据存储在硬盘上 iOS下主要有四种数据持久化方式 属性列表 对象归档 SQLite数据库 CoreData 数据持久化对的对比 1.属性列表.对象归档适合小数据 ...
- start-stop-daemon 命令
Usage: start-stop-daemon [<option> ...] <command> Commands: -S|–start — <argument> ...