Closed kingconan closed 9 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().
I also use it in listview, I solved this problem, maybe it have some bugs.
first add two members:
// when in listview , use this map to save collapsed status
private SparseArrayCompat
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();
}
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
I have commit it to github, hope it can help you. https://github.com/com314159/ExpandableTextViewInListView/tree/master
I have fix some bugs in listview, you can see the commit in the github. Thank you Manabu-GT
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
How to reset the collapse-state in a listview? When listview scrolling up and down, the reused textview's height display not right.