Nội dung:
- Tabs
- Custom adapter
--------------
1. Tabs:
- Sử dụng tabhost tạo ví dụ như sau
- Download icon của dự án:
https://drive.google.com/file/d/0B8tAQ0_sJKCSOExhcFpFY1VjTXM/view?usp=sharing
- Cấu trúc dự án:
- Mã nguồn XML: 4 tệp tin
  + Tệp tin activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/linelayout"       
       android:orientation="vertical"
        android:layout_width="match_parent"
       android:layout_height="match_parent">
       <TabWidget
           android:id="@android:id/tabs"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"/>
              <FrameLayout
                  android:id="@android:id/tabcontent"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"/>
       </LinearLayout>     
</TabHost>
  + Tệp tin photoslayout.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:orientation="vertical" >

    <TextView
        android:id="@+id/textViewPhotos"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="15dp"
        android:text="Photos here"
        android:textSize="18sp" />
</LinearLayout>
  + Tệp tin songslayout.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:orientation="vertical" >

    <TextView
        android:id="@+id/textViewSongs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="15dp"
        android:text="Songs here"
        android:textSize="18sp" />

</LinearLayout>
  + Tệp tin videoslayout.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:orientation="vertical" >

    <TextView
        android:id="@+id/textViewVideos"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="15dp"
        android:text="Videos here"
        android:textSize="18sp" />

</LinearLayout>

Tạo 3 tệp tin XML trong thư mục drawable: 3 tệp tin
  + Tệp tin icon_photos_tab.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/photos_gray"
          android:state_selected="true"/>
    <item android:drawable="@drawable/photos_white"/>
</selector>
  + Tệp tin icon_songs_tab.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/songs_gray"
          android:state_selected="true"/>
    <item android:drawable="@drawable/songs_white"/>
</selector>
  + Tệp tin icon_videos_tab.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/videos_gray"
          android:state_selected="true"/>
    <item android:drawable="@drawable/videos_white"/>
</selector>

- Mã nguồn java:
  + Tệp tin PhotosActivity.java:
package com.tabs;

import android.app.Activity;
import android.os.Bundle;

public class PhotosActivity extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.photoslayout);
       }
}
  + Tệp tin SongsActivity.java:
package com.tabs;

import android.app.Activity;
import android.os.Bundle;

public class SongsActivity extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.songslayout);
       }
}
  + Tệp tin VideosActivity.java:
package com.tabs;

import android.app.Activity;
import android.os.Bundle;

public class VideosActivity extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.videoslayout);
       }
}
  + Tệp tin MainActivity.java:
package com.tabs;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              TabHost tabhost = getTabHost();
             
              //Tabhost photos
              TabSpec photosSpec = tabhost.newTabSpec("Photos");
              photosSpec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
              Intent photosIntent = new Intent(this, PhotosActivity.class);
              photosSpec.setContent(photosIntent);
             
              //Tabhost songs
              TabSpec songsSpec = tabhost.newTabSpec("Songs");
              songsSpec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
              Intent songsIntent = new Intent(this, SongsActivity.class);
              songsSpec.setContent(songsIntent);
             
              //Tabhost videos
              TabSpec videosSpec = tabhost.newTabSpec("Videos");
              videosSpec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
              Intent videosIntent = new Intent(this, VideosActivity.class);
              videosSpec.setContent(videosIntent);
                          
              //Add all TabSpec to TabHost
              tabhost.addTab(photosSpec);
              tabhost.addTab(songsSpec);
              tabhost.addTab(videosSpec);
       }
}

- Tệp tin AndroidMainifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tabs"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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=".PhotosActivity"/>
        <activity android:name=".SongsActivity"/>
        <activity android:name=".VideosActivity"/>
    </application>

</manifest>

2. Custom adapter:
- Xem bài 10, phần 3: http://huongdan-laptrinh.blogspot.com/2015/08/bai-10-how-to-work-with-threads-files.html

Bài tập:
1.

2.