Manabu-GT / ExpandableTextView

Android's TextView that can expand/collapse like the Google Play's app description
Apache License 2.0
4.08k stars 791 forks source link

expandable textview in listview #1

Closed kingconan closed 9 years ago

kingconan commented 10 years ago

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 commented 10 years ago

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 commented 9 years ago

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 commented 9 years ago

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

com314159 commented 9 years ago

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

Manabu-GT commented 9 years ago

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