User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:filter

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.

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

Home»Sample Code

sample_code/filter.txt · Last modified: 2016/08/29 15:38 (external edit)