Need help implementing a search feature

Hi,

I have an app that allows students to enter in their homework assignments into a list however, I am trying to implement a search feature that allows the user to see assignments for only one subject eg. ‘Mathematics’.

The way I have implemented this thus far is added a ‘search’ button which, when pressed, activates the search mode.

image

When the search mode is activated, the user can choose a subject from the subject text input which then should parse the assignments list and add any assignments which contain that subject. This is the code I have so far:

Setting up variables:

image

Activation of search mode:

image

Subject selection:

image

Parsing algorithm:

image

The code is not running as expected; the list does not display the assignments associated with the subject. I have tried to debug the code and these are my findings:

  • When the search mode is activated, it is indeed returned as ‘true’.
  • The if statement within the for loop is also returns true when the subject is found in the subject.

Therefore, I am not sure why the code is not running as expected. Any help on this would be much appreciated. Here is a link to the project.

Thanks!

Any suggestions @muneer ?

Thanks! :slightly_smiling_face:

1 Like

Hey :wave: @jakeheron

How is your data structured? Are you using a table or list of objects?

2 Likes

I am using a lists. For each assignment ‘j’ within the assignments list, if ‘item’ is contained in ‘j’ then it should add j into the ‘assignments search’ list which has been initialized as an empty list.

1 Like

@jared @muneer do you guys have any suggestions on how I can resolve this issue?

Thanks!

I know I wasn’t notified but here’s my $0.02:

I looked at your project and it’s honestly just a lot of effort to add demo classes and set everything up to be able to test it. Perhaps you can make a copy and strip out a lot (e.g. sign in) and have all of the data set up, ready to go. That’s obviously work on your part… I just don’t have the time to add the demo data over and over while debugging it.

1 Like

One problem I see is you are using “set” instead of “insert” when you find a match, and I think you want to insert each match into the list not just change (set) the last one.

2 Likes

Thanks @tatiang for the feedback. I agree, it is time consuming but I need to implement the feature as this project is actually for my computer science internal assessment. Therefore, the examiner will need to be able to see how the user enters data without actually needing to do any themselves, hence the ‘demo’ button. I think whenever I ask I question on this forum, I will link a demo project containing only the screen in question and then just obviously copy any code back into the original project.

1 Like

Thank you very much @David_Wolber , this resolved the issue!

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.