Joel Keane

Greenhorn
+ Follow
since Jun 18, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joel Keane

I finally have working code:



Big thanks Steve and also JackyZhu from another forum for pointing me in the right directions. I have learnt a lot more about loops, booleans and arrays. Thank you
10 years ago
I have since worked out that I was trying to store a string in a boolean which was giving me the error.

If I change the code to :



I get an error in the "return namestring[i]" code for the 'i' value. If I move the line up under the "namestring[i] = name.toUpperCase().contains(tempname[i]);" (in the same brackets) I lose the error but the loop won't loop because it is closing the loop after the first pass. Any ideas how I can get around this?
10 years ago
Here is my latest effort:



I am trying to store the name values while in the loop and then return all the values after the loop has finished. I get an error of "Type mismatch: cannot convert from boolean to String" for the code and an error of "Type mismatch: cannot convert from String[] to boolean" for the code.

If you can offer anymore assistance that would be greatly appreciated. Like I said before, my java is quite basic. I have written this app purely in my own time for my workmates to use for free - java is not my profession (As you can tell lol)

Thanks
10 years ago
I have been looking into the loop more and think I know why it is only showing the first term. It is with the following code:



The "return" section is ending the loop - this is why it is only showing the first one and also why I get a "dead code" error for the "i++" as "i" is never incremented.

This being said, I still cannot work out how to return each "name" that contains a word form the spilt in its filename to my array.

I think I need to store each "name.toUpperCase().contains(tempname[i])" to a list and then once the for loop is finished checking all the words return all of the values. I just don't know how to do this.
10 years ago
I have also tried:



But still it only shows results for the first word only
10 years ago
Hi Steve,

I have had another look at the link you posted. I think I am very close. I believe I can use the ".split" function.

My new code is



The only problem is that this only searches on the first word in the search string. For instance if I put "black cat" as a search string it will bring up any file with "Black" in the title. I think it isn't checking every word in the string split. Can you please help me out with how I can achieve this?

Thanks,
Joel
10 years ago
Hi Steve,

Thanks for you help. I do understand that I need to split the search term up and check if they filenames contain any of the search string words. Unfortunately I am at a loss as to how I go about this. You are correct that searchname.searchname is a string that has been passed to the activity from a previous search screen. This is the search term that the user has entered.

Unfortunately my Java skills are not at the level that seems to be required to carry out this task. I understand the logic of what I need it to do, I just don't know how to go about this.
10 years ago
Hi,

I have a recursive search that uses the ".contains" function to find file names based on the search words entered. The only problem is that if the file name contains only one of the words it doesn't show up.

For example:

Keywords entered = "black cat"

If the title contains "black cat" in that specific order it returns the file name. However if the title only contains "cat" it doesn't return anything.

I need some way to break the search keywords up so that it finds all the files that contain any of the keywords.

Here is the section of code that handles the search:



Below is the full code for that activity:




Thank you in advance for any help you can offer
10 years ago
I have now solved my problem regarding how to exclude a directory and its files from the search results. FYI the folder that I wanted to exclude was called "Recent Files".

Here is my fixed code:



Hope this helps someone else out.
10 years ago
Hi Karthik,

There is one other feature I just thought of that you may be able to help me with. There is one sub directory that I do not wish to include in the file recursion. That is, I do not want any files from that sub directory to be included in the array.

The sub directory is: File(Environment.getExternalStorageDirectory() + "/RTIO/RecentFiles"));

I am thinking that I need to include something in this section of code:



I have tried a few things but cannot seem to get it to work. Are you able to point me in the right direction please?

Thanks heaps.
10 years ago
Hi Karthik,

Thank you! Thank you! Thank you!

I appreciate all the time and effort you put in to help me fix my recursive/search problems. I have also learned quite a few things regarding arrays etc and the logic behind them also. I have attached my new working code in case it might help someone else at a later date with a similar problem.

Once again, I can't thank you enough and I wish you all the best :-)

Kind regards,
Joel

My corrected code:

10 years ago
Thanks. Yes, I want the code to "walk" through all directories and sub directories and look for file names that contain the search term. I have changed my code to:



However now it seems not to apply the search string at all. It lists every file in all the directories and sub directories - even if there is a search term entered.

Thank you
10 years ago
Also, here is the FileArrayAdapter.java file:



Perhaps I need to do the filtering in here???
10 years ago
After further investigation I have found out that the search does work for certain letters or words. If you put in an "a" it will work or some words that are contained in file names will work. So it seems to be having a problem with the logic in searching the titles. Just thought I would add that in case it helps with your reply.
10 years ago
Hi Karthik,

Firstly let me say thank you very much for taking the time to go through my code and trouble shoot it - it is very much appreciated. Also, thank you for explaining a bit more on the logic of the Array. I have adapted your response to my code and am very close in having a solution. When I run my search code now and leave the search keyword blank it will now show the search results screen with all of all of the folders in the /RTIO folder. So you have helped me make it search recursively :-)

The only problem is that if I put a keyword in to search, the screen is blank - there are no results???

Here is my new adjusted code with the recursive search working. Can you please have a look and see why you think the filename filter might be causing problems when I put a search term in to check against file names?



I am thinking it has something to do with this code:



That is my filename filter that takes the search term and is run in the private void fill(File f) section. Can you see any reason why the recursion is working with no search term, but when I have a search word put in it returns a blank screen?

Thank you very much for your continuing help.

Kind regards,
Joel
10 years ago