Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

FAQArrayAdapter rows get reset upon scrolling #412

Open
Pooja-Mahadev-Soundalgekar opened this issue Mar 7, 2017 · 4 comments
Open

FAQArrayAdapter rows get reset upon scrolling #412

Pooja-Mahadev-Soundalgekar opened this issue Mar 7, 2017 · 4 comments

Comments

@Pooja-Mahadev-Soundalgekar
Copy link

Pooja-Mahadev-Soundalgekar commented Mar 7, 2017

When a row in the FAQArrayAdapter is selected, the TextView "faqDesc" becomes visible, showing the description of that item. But, when you scroll up or down the ArrayAdapter, the row gets reset, thus making the "faqDesc" TextView invisible again.

Steps to reproduce:

  1. Go to any activity that uses the FAQArrayAdapter. For example, go to SAFETY TOOLS -> UNWANTED ATTENTION.
  2. Click on any row. This will make the description visible.
  3. Scroll down till the row you selected is not seen on the screen.
  4. Scroll back up to the row you had selected before. The description is now invisible.

The expected outcome should be that each row should retain its state even on scrolling. Rows that were selected and expanded to show their description should remain expanded when the user scrolls and then comes back to the same row.

I have attached 2 videos. One shows the bug and the other shows what it looks like after the fix.

The bug:
bug

The fix:
fix
@sandarumk I would like to work on this. Can I send a PR fixing this?

@Pooja-Mahadev-Soundalgekar
Copy link
Author

@sandarumk My proposed solution is to store the state (whether the description is visible or not) of each item in the array adapter in an array faqVisibilities (just like faqTitles and faqDescriptions) and in the getView() function of FAQArrayAdapter.java, along with setting the title and the description, we can set the visibility of the description also based on the value of faqVisiblities at that position. I have already written this code and the video of this is attached with the question.

@codingblazer
Copy link
Member

Hey @Pooja-Mahadev-Soundalgekar, your solution looks good but can be further optimised. It would be better to store just the expanded textviews in the Arraylist instead of storing state of every textview since this array will be called many times. There is no need to store the already collapsed Textview.
Check if textview to be expanded is in Arraylist, if yes do nothing, if no add it.
Check if textview to be collapsed is in Arraylist, if yes remove it from arraylist, if no do nothing.

@sandarumk
Copy link

This is a valid issue you can go ahead. You can discuss here and come to a decision on how to implement. Ping me if you are stuck.

@Pooja-Mahadev-Soundalgekar
Copy link
Author

The solution I propose is to use a HashSet<Integer> expandedPositions. If a position is present in this set, it means that it has been expanded by the user. In the getView() function, we check if the current position is present in this HashSet and change the view depending on this. When the user clicks on an item in the array adapter, depending on whether the row is expanded or collapsed, we insert or delete that position from this HashSet.

@sandarumk What do you think of this solution?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants