1

I'm use recyclerview and holder adapter. This have textview and maxlines is 4. I want to if user click then expand again click then collapse.

My codes is working but i have an issue; When i click textview this going to expanded work fine but when i was scroll to down list some textview is automatic expanded state(but i did not touch them).

XML:

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/uiPadding_4dp"
    android:maxLines="4"/>

Holder:

private final List<Integer> listReadMore = new ArrayList<>();

public void onBind(final Holder holder, final int position) {
    final Obj obj = getObj(position);
    final int id  = obj.id();
    final String text = obj.text();

    holder.text.post(new Runnable() {
        @Override
        public void run() {
            if(holder.text.getLineCount() >= maxLine)
                listReadMore.add(id);
        }
    });

    holder.text.setText(Kit.doHtmlText(text));
    holder.text.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(listReadMore.contains(id)){
                ObjectAnimator animation = ObjectAnimator.ofInt(
                        holder.text,
                        "maxLines",
                        holder.text.getLineCount());
                animation.setDuration(600);
                animation.start();
                listReadMore.remove(listReadMore.indexOf(id));
            }else{
                ObjectAnimator animation = ObjectAnimator.ofInt(holder.text, "maxLines", 4);
                animation.setDuration(400);
                animation.start();
                listReadMore.add(id);
            }
        }
    });
}

When i was use simplify code I'm having the same problem again..

holder.text.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        holder.text.setMaxLines(100);
    }
});

I was use https://github.com/Manabu-GT/ExpandableTextView this api but have some issue on recyclerview.

I dont know what can i do..

kibar
  • 822
  • 3
  • 17
  • 37

0 Answers0