This shows you the differences between two versions of the page.
sample_code:filter [2016/08/29 07:38] administrator indented code |
sample_code:filter [2016/08/29 15:38] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | **Filter Items** | ||
- | |||
- | This sample shows how to filter the files and folders in sdcard directory. | ||
- | You can also filter any other items on a List View from this sample. | ||
- | <code JavaScript Filter.js> | ||
- | app.ShowProgress(" | ||
- | //List Files and folders on the sdcard | ||
- | |||
- | var myArray = app.ListFolder(app.GetInternalFolder()).sort(); | ||
- | //Called when application is started. | ||
- | function OnStart() | ||
- | { | ||
- | app.ShowProgress(" | ||
- | //Create a layout with objects vertically centered. | ||
- | lay = app.CreateLayout(" | ||
- | |||
- | //Create a text label and add it to layout. | ||
- | txt = app.CreateTextEdit("", | ||
- | txt.SetTextSize(32); | ||
- | txt.SetHint(" | ||
- | txt.SetOnChange(change); | ||
- | lay.AddChild(txt); | ||
- | //Create Check Box | ||
- | chk = app.CreateCheckBox(" | ||
- | lay.AddChild(chk); | ||
- | //Create List | ||
- | lst = app.CreateList(myArray, | ||
- | lst.SetOnTouch(tch); | ||
- | lay.AddChild(lst); | ||
- | //Add layout to app. | ||
- | app.AddLayout(lay); | ||
- | app.HideProgress(); | ||
- | } | ||
- | |||
- | function change() | ||
- | { | ||
- | if (chk.GetChecked()) | ||
- | { | ||
- | insens(); | ||
- | } | ||
- | else | ||
- | { | ||
- | sens(); | ||
- | } | ||
- | } | ||
- | |||
- | function tch(it) | ||
- | { | ||
- | if (app.IsFolder(app.GetInternalFolder() + "/" | ||
- | { | ||
- | app.ShowPopup(it, | ||
- | } | ||
- | else | ||
- | { | ||
- | app.OpenFile(app.GetInternalFolder() + "/" | ||
- | } | ||
- | } | ||
- | |||
- | function sens() | ||
- | { | ||
- | peo = []; | ||
- | s = ""; | ||
- | text = txt.GetText(); | ||
- | for (i = 0; i < myArray.length; | ||
- | { | ||
- | if (myArray[i].indexOf(text) != -1) | ||
- | { | ||
- | peo.push(myArray[i]); | ||
- | } | ||
- | } | ||
- | lst.SetList(peo); | ||
- | } | ||
- | |||
- | function insens() | ||
- | { | ||
- | peo = []; | ||
- | s = ""; | ||
- | text = txt.GetText().toLowerCase(); | ||
- | for (i = 0; i < myArray.length; | ||
- | { | ||
- | if (myArray[i].toLowerCase().indexOf(text) != -1) | ||
- | { | ||
- | peo.push(myArray[i]); | ||
- | } | ||
- | } | ||
- | lst.SetList(peo); | ||
- | } | ||
- | </ | ||
- | |||
- | [[: |