一、简介

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. Android res资源文件夹的知识积累

    Android的开发框架耦合性还是比较低的,逻辑和布局被原生分开了.在Eclipse一般代码写在src文件夹下,资源等写在res文件夹下. drawable文件夹:该文件夹有很多变种,主要是为了适配A ...

  2. System.Web.Mvc.Html 命名空间小计(转)

    最近在看MVC框架,发现这个博文对初学者可能有帮助,故转之. 1,Html.Action    使用指定参数调用指定子操作方法并以 HTML 字符串形式返回结果. Html.Action() < ...

  3. Masonry 控件详解

    1.   Masonry的属性 @property (nonatomic,strong,readonly)MASConstraint *left; //左侧 @property(nonatomic,s ...

  4. css 利用border属性制作箭头 Using Borders to Make Pure CSS Arrows

    不再需要多余的图片 用border属性自然能创造箭头效果 学习地址:http://tech.patientslikeme.com/2010/11/09/using-borders-to-make-pu ...

  5. 2016/01/19 javascript学习笔记-name属性

    1. name属性只在少数html元素中有效:包括表单.表单元素.<iframe>和<img>元素. 基于name属性的值选取html元素,可以使用document对象的get ...

  6. VIM 同义词

    vim-online-thesaurus A Vim plugin for looking up words in an online thesaurus, Now thesaurus.com 一.原 ...

  7. 将博客搬迁至CSDN

    CSDN不给我搬家就算了....我自己搬= = http://blog.csdn.net/ourfutr2330

  8. makefile-0711-168 SEVERE ERROR: Input file:

    ld: 0711-168 SEVERE ERROR: Input file: /cicm/commlib/include        Input files must be regular file ...

  9. 第10条:始终要覆盖toString

    java.lang.Object的toString方法的实现: public String toString() { return getClass().getName() + "@&quo ...

  10. leetcode problem 37 -- Sudoku Solver

    解决数独 Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated ...