This shows you the differences between two versions of the page.
sample_code:filter [2016/07/24 09:54] titus |
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(" | ||
- | // | ||
- | |||
- | var myArray = app.ListFolder(app.GetInternalFolder()).sort(); | ||
- | // | ||
- | function OnStart() | ||
- | { | ||
- | app.ShowProgress(" | ||
- | // | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | // | ||
- | txt = app.CreateTextEdit( "", | ||
- | txt.SetTextSize( 32 ); | ||
- | txt.SetHint(" | ||
- | txt.SetOnChange(change) | ||
- | lay.AddChild( txt ); | ||
- | // | ||
- | chk =app.CreateCheckBox(" | ||
- | lay.AddChild(chk) | ||
- | // | ||
- | lst = app.CreateList(myArray, | ||
- | lst.SetOnTouch(tch) | ||
- | lay.AddChild(lst) | ||
- | // | ||
- | app.AddLayout( lay ); | ||
- | app.HideProgress(); | ||
- | } | ||
- | |||
- | function change(){ | ||
- | if(chk.GetChecked()){insens()} | ||
- | else{sens()} | ||
- | |||
- | } | ||
- | |||
- | function tch(it){ | ||
- | if(app.IsFolder(app.GetInternalFolder()+"/" | ||
- | else{ | ||
- | app.OpenFile(app.GetInternalFolder()+"/" | ||
- | } | ||
- | } | ||
- | |||
- | function sens(){ | ||
- | peo = [] | ||
- | s ="" | ||
- | text= txt.GetText() | ||
- | for(i=0; | ||
- | if(myArray[i].indexOf(text)!=-1){ | ||
- | 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) | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | [[sample_code: |