Filtering subject options in Android based on student's score?

I’m building an Android app that needs to show a list of subjects a student can take based on their score. Here’s what I want to do:

  1. Have a list of about 100 subjects, each with a required score
  2. When a student enters their score, only show subjects they qualify for

For example, if subjects are:

  • Math (score: 25)
  • History (score: 20)
  • Science (score: 30)
  • Art (score: 15)

And a student enters 22, they should see:

  • History
  • Art

But not Math or Science, as their score is too low.

I’ve tried using a ListView and ArrayAdapter, but I’m stuck on how to filter the list based on the student’s input. Any ideas on how to make this work? I’m new to Android development, so simple explanations would be great. Thanks!

For your filtering requirement, I’d suggest using a RecyclerView with a custom adapter. This approach is more efficient for large datasets and offers better performance than ListView.

Here’s a basic implementation idea:

  1. Create a Subject class to hold subject details (name, required score).
  2. In your activity, maintain a list of all subjects.
  3. Implement a custom RecyclerView.Adapter.
  4. When the student enters their score, filter the main list in your adapter.
  5. Use notifyDataSetChanged() to update the RecyclerView.

This method allows for smooth scrolling and efficient memory usage, especially with your 100+ subjects. It also provides flexibility for future features like sorting or additional filtering criteria.

Remember to handle edge cases, like no matching subjects or invalid score inputs. Good luck with your app!

hey, have u thought about using a hashmap? it lets u store subjects with scores and loop thru to compare the student’s score to each requirement. then, u can add qualifying subjects to a new list for display. it’s a simple way to filter.

Hey there, fellow app developer! :wave: Your idea sounds super cool and useful for students. I totally get why you’re using ListView and ArrayAdapter - they’re great for displaying lists. But yeah, filtering can be a bit tricky at first.

Have you thought about using a RecyclerView instead? It’s more flexible and efficient, especially for longer lists like yours. You could create a custom adapter that takes the student’s score as a parameter and only adds qualifying subjects to the list.

Another approach could be using a FilterableListAdapter. It lets you implement custom filtering logic pretty easily. You’d just need to override the performFiltering() method to check each subject’s required score against the student’s input.

Curious - how are you storing the subject data right now? If it’s in a database, you could even do the filtering at the query level before populating your list.

What do you think about these ideas? Let me know if you want me to explain any part in more detail!