android SDK中提供了TabHost使用起來很方便, 但是當tab比較多的時候,就會擠在一起,而不能橫向的滾動比較麻煩.
于是我嘗試的制作了一個簡單的使用Gallery來代替TabHost的例子, 確實夠簡單的,自娛自樂.....僅供參考

使用BroadcastReceiver來切換不同的Tab
public class ChangeTabBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int index = intent.getExtras().getInt(CURRENT_TAB_INDEX);
Log.i(TAG, "onReceive index = " + index);
// setCurrentTab(index);
topBar.setSelection(index);
startGroupActivity(titleList.get(index).toString(),
(Intent) intentList.get(index));
}
}
沒有詳細研究SDK中的TabHost實現機制, 使用起來還是有些不方便的地方
public class GalleryTabActivityDemo extends GalleryTabactivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setDelegate(new SliderBarActivityDelegateImpl());
for (int i = 0; i < 14; i++) {
Intent intent;
if (i % 2 == 0)
intent = new Intent(this, DemoActivity1.class);
else
intent = new Intent(this, DemoActivity2.class);
this.addTab("title" + i, android.R.drawable.star_on, intent);
}
//必須在addTab后調用commit, 有點麻煩, 將來會找更好的辦法
super.setup();
}
//可自定義切換tab時觸發的操作
private class SliderBarActivityDelegateImpl extends
SliderBarActivityDelegate {
protected void onTabChanged(int tabIndex) {
Log.d("onTabChanged", "" + tabIndex);
}
}
}
最近工作比較忙,沒太多時間學習android,將來會慢慢改善, 先湊合用, 拋塊磚先, 各位有玉的使勁砸, 金條也行
下載
posted @
2010-05-13 15:46 小強 閱讀(2158) |
評論 (0) |
編輯 收藏
學習android的練習小軟件.
制作文件管理器的初衷是發現G1上并沒有隨系統附帶文件瀏覽軟件,
考慮到電子書,媒體播放器或其它一些軟件會使用到文件瀏覽,選擇文件或文件夾, 所以先做了這個文件管理工具并封裝一些參數供第三方程序調用
應用很簡單, 只是把手機和SD卡中的文件列出來, 支持圖片和mp3的簡單預覽. 未來會有更多的功能擴充進來. 歡迎大家試用并提出意見.
--------------------------------------------------------4月更新0.3版
--------------------------------------------------------------------
自從上次更新后工作太忙,半年沒玩兒ANDROID了, 最近剛剛閑下來, 繼續完善文件管理器
順便封裝了一些其它的widget, 整理后再發上來
看著網上鋪天蓋地的各種android應用, 再看看我這個小破軟件, 實在有點拿不出手, 但既然做了就得不斷完善下去
目標是做一個封裝widget的集合, 方便開發者使用
1, 使用線程和handler message機制讀取文件列表, 提升軟件性能
2, 解決文件列表多次滾動后速度下降的問題
3, 打開文件使用手機關聯的應用
4, 增加文件縮略圖顯示


--------------------------------------------------------10月27日更新0.2版
--------------------------------------------------------------------
1. 0.2版主要增加了一些使用者的功能, 增加了收藏夾功能, 方便用戶快速的瀏覽到經常訪問的文件或文件夾
2. 修改了一些for developer的bug


-------------------------------------------------------- 0.1版
--------------------------------------------------------------------



-------------------------------------------------------------------- for
developer
--------------------------------------------------------------------
G1上并沒有隨系統附帶文件瀏覽軟件, 考慮到電子書,媒體播放器或其它一些軟件會使用到文件瀏覽,選擇文件或文件夾,
所以先做了這個文件管理工具并封裝一些參數供第三方程序調用,可以做為插件形式使用
把文件管理器封裝起來并使用intent機制設置瀏覽參數和調用
目前暫不支持多文件選擇, 將在下一版中發布
調用程序示例
1
Button button2
=
(Button) findViewById(R.id.but2);
2
button2.setOnClickListener(testFileManager);
1
private
OnClickListener testFileManager
=
new
OnClickListener() {
2
public
void
onClick(View v) {
3
Intent intent
=
new
Intent(
"
net.uiiang.android.alkaid.FILEMANAGER
"
);
4
5
//
參數root_directory, 設置瀏覽的根目錄, 例如設置
/sdcard則只允許程序瀏覽sd卡中的內容, 當程序回退上層文件夾到/sdcard后不再向上回退
6
//
參數類型為字符串, 默認為"/"(根目錄)
7
intent.putExtra(
"
root_directory
"
,
"
/
"
);
8
9
//
參數exclude_directory, 設置不顯示的目錄, 例如設
置"/data", "/dev", 則"/data", "/dev"這兩個目錄不會顯示給用戶
10
//
參數類型為字符串數組, 默認不排除任何文件夾
11
intent.putExtra(
"
exclude_directory
"
,
12
new
String[] {
"
/data
"
,
"
/dev
"
});
13
14
//
參數thrid_party_call, 當第三方程序調用時, 必須設置
此參數為true, 否則下面幾個參數不起作用
15
//
參數類型為boolean, 默認為false, 會顯示以下參數可設置的
所有菜單(除 選擇菜單)
16
intent.putExtra(
"
thrid_party_call
"
,
true
);
17
18
//
參數directory_show_type, 目錄瀏覽方式
19
//
參數類型為 int, 默認為0
20
//
0 : 顯示文件和文件夾(默認)
21
//
1 : 只顯示文件
22
//
3 : 只顯示文件夾
23
intent.putExtra(
"
directory_show_type
"
,
0
);
24
25
//
參數use_menu_items, 設置顯示的預置菜單
26
//
參數類型為:int數組
27
//
菜單列表:
28
//
1 : 上下文菜單-打開 (文件夾)
29
//
2 : 上下文菜單-刪除
30
//
3 : 上下文菜單-詳細信息
31
//
4 : 上下文菜單-復制
32
//
5 : option菜單-粘貼
33
//
6 : option菜單-新建文件夾
34
//
99: 上下文菜單-選擇 , 若需要文件管理器返回一個選中的文件路
徑, 則必須設置此菜單
35
//
當用戶點擊此菜單后, 文件管理器退出并返回給調用程序一個字符串數
組, 數組中包含文件路徑信息
36
intent.putExtra(
"
use_menu_items
"
,
new
int
[] {
99
});
37
38
//
參數show_info_in_list, 是否在瀏覽文件中顯示簡單的
信息, 如文件夾中包含多少子文件夾和文件
39
//
默認為true
40
intent.putExtra(
"
show_info_in_list
"
,
false
);
41
42
//
參數show_file_extension, 是否顯示文件后綴名
43
//
默認為 true
44
intent.putExtra(
"
show_file_extension
"
,
false
);
45
46
//
參數use_simple_view, 是否使用簡單文件預覽
47
//
用戶單擊文件后可以簡單的預覽文件內容, 目前支持圖片和音樂文件
48
//
默認為 true
49
intent.putExtra(
"
use_simple_view
"
,
false
);
50
51
//
參數animation_show_list, 是否使用動態效果顯示文
件列表, 目前只支持向下卷簾式的效果
52
//
默認為true
53
intent.putExtra(
"
animation_show_list
"
,
true
);
54
55
//
參數mutiple_select, 是否支持多選, 為true可以一次
性選擇多個文件或目錄
56
//
默認為false
57
intent.putExtra(
"
mutiple_select
"
,
false
);
58
59
startActivityForResult(intent, SELECT_FILE);
60
}
61
};
通過startActivityForResult調用文件管理器, 并使用上下文菜單選擇文件或文件夾

點擊"選擇"后, 返回到調用程序
1
@Override
2
protected
void
onActivityResult(
int
requestCode,
int
resultCode, Intent data) {
3
super
.onActivityResult(requestCode, resultCode, data);
4
if
(requestCode
==
SELECT_FILE) {
5
if
(resultCode
==
RESULT_OK) {
6
//
參數名為selected_uri, 得到字符串數組中包含文件路徑
7
String[] selectArr
=
data.getExtras().getStringArray(
8
"
selected_uri
"
);
9
if
(selectArr
!=
null
) {
10
String selectFile
=
""
;
11
for
(String string : selectArr) {
12
System.out.println(
"
you select =
"
13
+
data.getExtras().getStringArray(
14
"
selected_uri
"
));
15
}
16
}
17
18
}
19
}
20
}

posted @
2010-05-05 17:10 小強 閱讀(338) |
評論 (0) |
編輯 收藏