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

expandable textview in listview #1

Closed
kingconan opened this issue Aug 19, 2014 · 5 comments
Closed

expandable textview in listview #1

kingconan opened this issue Aug 19, 2014 · 5 comments
Assignees
Labels
Milestone

Comments

@kingconan
Copy link

How to reset the collapse-state in a listview?
When listview scrolling up and down, the reused textview's height display not right.

@Manabu-GT
Copy link
Owner

I didn't originally intend this to be used within a ListView where the view gets recycled.
However, I believe you could try the following method to reset the collapsed state within your ListView.
(I never tested it, so it might not work.)

Reset the ExpandableTextView's height to its original value within your getView() method inside your adapter, then call setText() and requestLayout().

@com314159
Copy link

I also use it in listview, I solved this problem, maybe it have some bugs.

  1. first add two members:

    // when in listview , use this map to save collapsed status
    private SparseArrayCompat mConvertTextCollapsedStatus = new SparseArrayCompat();
    private int mPosition;

  2. add a method:

       public void setConvertText(int position,String text) {
    boolean isCollapsed = mConvertTextCollapsedStatus.get(position, true);
    mPosition = position;
    clearAnimation();
    mCollapsed = isCollapsed;
    if (mButton != null) {
        mButton.setImageDrawable(mCollapsed ? mExpandDrawable : mCollapseDrawable);
    }
    clearAnimation();
    if (mCollapsed) {
        if (mTv!=null){
            mTv.setMaxLines(mMaxCollapsedLines);
        }
    } else {
        if (mTv!=null) {
            mTv.setMaxLines(Integer.MAX_VALUE);
        }
    }
    this.getLayoutParams().height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
    setText(text);
    requestLayout();
    

    }

  3. in onClick Method, add

    mCollapsed = !mCollapsed;
    mConvertTextCollapsedStatus.put(mPosition, mCollapsed);
    

I have test it , it works in listview.

I will commit it to github next time

@com314159
Copy link

I have commit it to github, hope it can help you.
https://github.com/com314159/ExpandableTextViewInListView/tree/master

@com314159
Copy link

I have fix some bugs in listview, you can see the commit in the github.
Thank you Manabu-GT

@Manabu-GT Manabu-GT self-assigned this Nov 7, 2014
@Manabu-GT Manabu-GT added the bug label Nov 7, 2014
@Manabu-GT Manabu-GT added this to the v0.1.1 milestone Nov 7, 2014
@Manabu-GT
Copy link
Owner

The fix is in v0.1.1 and now published to the maven central.
It should go live within a day.

Thank you for you guys's help.

Manabu

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

No branches or pull requests

3 participants