User Tools

Site Tools


sample_code:filter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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("Loading..."+app.GetInternalFolder()) +app.ShowProgress("Loading..." + app.GetInternalFolder()) 
-//List Files and folders on the sdcard+//List Files and folders on the sdcard
  
-var myArray = app.ListFolder(app.GetInternalFolder()).sort(); +var myArray = app.ListFolder(app.GetInternalFolder()).sort(); 
-//Called when application is started+//Called when application is started
-function OnStart()+function OnStart()
 { {
-    app.ShowProgress("Loading..."+app.GetInternalFolder()) +  app.ShowProgress("Loading..." + app.GetInternalFolder()) 
-    //Create a layout with objects vertically centered+  //Create a layout with objects vertically centered
-    lay = app.CreateLayout( "linear", "TopCenter,FillXY" );    +  lay = app.CreateLayout("linear", "TopCenter,FillXY");
  
-    //Create a text label and add it to layout+  //Create a text label and add it to layout
-    txt = app.CreateTextEdit( "",1,.1,"Center,Singleline" ); +  txt = app.CreateTextEdit("", 1, .1, "Center,Singleline"); 
-    txt.SetTextSize( 32 ); +  txt.SetTextSize(32); 
-    txt.SetHint("filter"+  txt.SetHint("filter"); 
-    txt.SetOnChange(change) +  txt.SetOnChange(change); 
-    lay.AddChild( txt ); +  lay.AddChild(txt); 
-    //Create Check Box +  //Create Check Box 
-    chk =app.CreateCheckBox("Case insensitive") +  chk = app.CreateCheckBox("Case insensitive"); 
-    lay.AddChild(chk) +  lay.AddChild(chk); 
-    //Create List +  //Create List 
-    lst = app.CreateList(myArray,1,null) +  lst = app.CreateList(myArray, 1, null); 
-    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()) 
 +  { 
 +    insens()
 +  
 +  else 
 +  { 
 +    sens(); 
 +  }
 } }
  
-function tch(it){ +function tch(it) 
-if(app.IsFolder(app.GetInternalFolder()+"/"+it)){app.ShowPopup(it,"Short,Bottom")} +
-else{ +  if (app.IsFolder(app.GetInternalFolder() + "/" + it)) 
-app.OpenFile(app.GetInternalFolder()+"/"+it,null,"Select Application") +  { 
-}+    app.ShowPopup(it, "Short,Bottom")
 +  
 +  else 
 +  
 +    app.OpenFile(app.GetInternalFolder() + "/" + it, null, "Select Application"); 
 +  }
 } }
  
-function sens(){ +function sens() 
-peo = [] +
-="" +  peo = []; 
-text= txt.GetText() +  = ""; 
-for(i=0;i<myArray.length;i++){ +  text = txt.GetText(); 
-if(myArray[i].indexOf(text)!=-1){ +  for (i = 0; i < myArray.length; i++) 
- 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;i<myArray.length;i++){ 
-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; i++)
 +  {
 +    if (myArray[i].toLowerCase().indexOf(text) != -1)
 +    {
 +      peo.push(myArray[i]);
 +    }
 +  }
 +  lst.SetList(peo);
 } }
 </code> </code>
  
 +[[:|Home]]>>[[sample_code:|Sample Code]]\\
sample_code/filter.1469271338.txt.gz · Last modified: 2016/07/23 18:55 (external edit)