一、简介

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标签的更多相关文章

  1. ANDROID_MARS学习笔记_S01原始版_005_RadioGroup\CheckBox\Toast

    一.代码 1.xml(1)radio.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  2. ANDROID_MARS学习笔记_S01原始版_004_TableLayout

    1.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android ...

  3. ANDROID_MARS学习笔记_S01原始版_003_对话框

    1.AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest ...

  4. ANDROID_MARS学习笔记_S01原始版_002_实现计算乘积及menu应用

    一.代码 1.xml(1)activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

  5. ANDROID_MARS学习笔记_S01原始版_001_Intent

    一.Intent简介 二.代码 1.activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.co ...

  6. ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER005_用广播BroacastReciever实现后台播放不更新歌词

    一.代码流程1.自定义一个AppConstant.LRC_MESSAGE_ACTION字符串表示广播"更新歌词" 2.在PlayerActivity的onResume()注册Bro ...

  7. ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER004_同步显示歌词

    一.流程分析 1.点击播放按钮,会根据lrc名调用LrcProcessor的process()分析歌词文件,得到时间队列和歌词队列 2.new一个hander,把时间队列和歌词队列传给自定义的线程类U ...

  8. ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER003_播放mp3

    一.简介 1.在onListItemClick中实现点击条目时,跳转到PlayerActivity,mp3info通过Intent传给PlayerActivity 2.PlayerActivity通过 ...

  9. ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件

    一.简介 1.在onListItemClick()中new Intent,Intent以存储序列化后的mp2Info对象作为参数,启动serivce 2.DownloadService在onStart ...

随机推荐

  1. 简单测试IIS下的UrlRewrite技术

    UrlRewrite即地址变换.它可以实现静态功能方便搜索引擎收录,比如http://***/news.asp?corangeid=11它可以变为htt://***/news-11.html.这样还实 ...

  2. Spring引用测试

    上下文 using System; using Spring.Core; using Spring.Aop; using System; using Spring.Core; using Spring ...

  3. SQL Server(高级) 关键字的使用 二

    二, 高级 关键字 -- 使用介绍 8,Top 的使用(Top子句返回记录的数目) select top number|percent column_name(s) from table_name 或 ...

  4. asp.net连接mysql数据库

    方法一:使用MySQL推出的MySQL Connector/Net组件, 该组件是MySQL为ADO.NET访问MySQL数据库设计的.NET专用访问组件.完成该组件后,需要在项目中引用这个组件,也可 ...

  5. Spring切面处理

    切面类DictionaryAOP 里面有一个全局变量systemTestDomain <bean id="dictionaryAOP" class="test.Di ...

  6. 12天学好C语言——记录我的C语言学习之路(Day 11)

    12天学好C语言--记录我的C语言学习之路 Day 11: 因为指针部分比较的难,所以我们花费的时间也是最长的,希望大家耐的住性子,多多理解,多多打代码.好了,废话不多说,来看第11天的学习. //编 ...

  7. ajax和jsonp的封装

    一直在用jQuery的ajax,跨域也是一直用的jQuery的jsonp,jQuery确实很方便,$.ajax({...})就可以搞定. 为了更好的理解ajax和jsonp,又重新看了下书,看了一些博 ...

  8. json,serialze之格式

    <?php echo 'array-json:' . "\n"; $arr = array('key1'=>'value1', 'key2' => 'value2 ...

  9. Cache的Add之委托解说

    正文 想了想还是写了吧,虽然知识含量比较低..... 获取数据放到缓存中,自己用Add添加的结果老是报参数错误,我擦咧,自己还总感觉是委托的问题.              call.Invoke(& ...

  10. object-fit: 炒鸡方便的图片居中方法

    今天在项目中遇到图片居中的问题,嗯,之前也有写过解决这个问题的文章,有n种方法.不过今天要说一个新的方案:object-fit ,嗯,这个才是真的方便的方案啊. 先看预览: object-fit 只能 ...