Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand state gone after you perform scrolling #6

Open
yccheok opened this issue Oct 10, 2013 · 2 comments
Open

Expand state gone after you perform scrolling #6

yccheok opened this issue Oct 10, 2013 · 2 comments

Comments

@yccheok
Copy link

yccheok commented Oct 10, 2013

Step to reproduce

  1. Tap on the 1st item to expand.
  2. Scroll to the bottom
  3. Scroll to the top
  4. The 1st item expand state is gone.
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.list_item, null);
        }

        ((TextView)convertView.findViewById(R.id.title)).setText(getItem(position));

        // Resets the toolbar to be closed
        View toolbar = convertView.findViewById(R.id.toolbar);
        ((LinearLayout.LayoutParams) toolbar.getLayoutParams()).bottomMargin = -50;
        toolbar.setVisibility(View.GONE);

        return convertView;
    }

I guess this is cause by View re-using. However, if we remove the code

        toolbar.setVisibility(View.GONE);

We will encounter another set of problem

  1. Tap on the 1st item to expand.
  2. Scroll to the bottom
  3. We will encounter some items other than 1st is expanded.
@sheamartinson
Copy link

I am quite new to Android development (4 days and counting now...), so forgive me if this workaround is very pedestrian or inefficient, but it has worked OK for me (and a lot of people seem to be encountering this problem):

Since my ListView is populating objects, I added an 'expanded' variable which is set to true by the onItemClickListener. Inside my BaseAdapter I check if the object is expanded and set the bottomMargin/visibility accordingly. I guess it has the added benefit of preserving the state of the expansion when the fragment/activity is resumed as well, but obviously it comes at a bit of a performance cost.

@lorenzos
Copy link

lorenzos commented Jun 3, 2014

@N00BFACE I solved the same way, and so I don't think the persistence of the expanded state should be a task of the code in that repository. For me, this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants