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