在android 上動態讀取folder and file, 類OpenDialog vcl |
|
fred
一般會員 發表:14 回覆:40 積分:10 註冊:2002-06-15 發送簡訊給我 |
現在大家都用智慧型手機了, 我分享大家一定會用到的一段相常實際好用的功能, android 想要匯入一些sdcard file 或是開啟自己的 SqLite database, 就像 vcl TOpenDialog.
用TPanel 當Owner 放上兩個ToolBar, 一個在Top,一個在Bottom ,中間放一個 ListBox align 設為client,, 但在ListBox之上放一個Label , Caption 顯示所在路徑 procedure TfmMain.WorkBackPath(lPath: string; ListBox: TListBox; PathLabel: TLabel); var files, folders: TStringDynArray; c, i: integer; LItem: TListBoxItem; begin PathLabel.Text := lPath; // folders := TDirectory.GetDirectories(lPath); { 以下為填入Folder } TArray.Sort ListBox.Clear; ListBox.BeginUpdate; for c := 0 to Length(folders) - 1 do begin LItem := TListBoxItem.Create(ListBox); // folder 加圖像 LItem.ItemData.Bitmap.Assign(Image1.Bitmap); LItem.ItemData.Text := ExtractFileName(folders[c]); LItem.ItemData.Detail := folders[c]; LItem.TagString := 'folder'; ListBox.AddObject(LItem); end; { 以下為files } files := TDirectory.GetFiles(lPath); // System.Generics.Collections, Generics.Defaults TArray.Sort for i := 0 to Length(files) - 1 do begin LItem := TListBoxItem.Create(ListBox); LItem.ItemData.Text := ExtractFileName(files[i]); LItem.ItemData.Detail := files[i]; LItem.TagString := 'file'; ListBox.AddObject(LItem); end; // ListBox.EndUpdate; end; ============================================= 如下方法呼叫使用, 在未呼叫時, 把Panel.visible 設為 false, path='/mnt/sdcard/download' 做為預設值, 並在MainForm 的OnKeyUP event (Key = vkHardwareBack) 時, 動態改path 就能逹到更改path Panel3.Visible := true; path := ExtractFileDir(path); WorkBackPath(path, ListBox2, Label1); ============================================== mFileName := trim(ListBox2.ListItems[ListBox2.ItemIndex].Text) // 所選的檔案 |
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
|
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |