Thursday, 22 August 2013

Returning multiple array values from loop

Returning multiple array values from loop

I have an activity in my app that takes a searchword and returns file
names that contain that search term. I am trying to modify this code so
that it can split a search term and show files that contain any of the
search terms. For instance if the search term is "big dog" it will return
files that have "big" in the title and also files that contain "dog" in
the title.
The part of the code is:
if (f.isDirectory()){
return true; // Don't discard any subdirectories
}
else {
String delimiter = " +"; /* delimiter */
searchname.searchname = searchname.searchname.toUpperCase();
//Split the search string
String [] tempname = searchname.searchname.split(delimiter);
//Array for the file names to be stored
boolean[] namestring = new boolean[tempname.length];
//Counter
int count;
count = 0;
for(int i=0; i<tempname.length; i++)
{
//While i is less than tempname size store filename to
namestring array
namestring[i] = name.toUpperCase().contains(tempname[i]);
//Add one to count
count = +1;
//Once count = tempname length you can return all of
the array values
if (count == tempname.length){
return namestring[i];
}
}
}
return false;
My java is pretty basic and I might be missing something very obvious.
Thank you very much for your help

No comments:

Post a Comment