question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TextView not expanding or collapsing when using ExpandableTextView

See original GitHub issue

Hi,

Thanks for creating this ExpandableTextView, it is exactly what I am looking to do, however, I’m not sure what I am missing because the textview is not expanding or collapsing for me.

I have the following ExpandableTextView in my layout:

<at.blogc.android.views.ExpandableTextView
                android:id="@+id/tv_JobDesc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textColor="@color/laborswipe_darkgray"
                android:text="aasdf
                 a
                 a
                 a
                 a
                 "
                android:maxLines="5"
                android:ellipsize="end"
                android:background="@color/white"/>

I am trying to expand the ExpandableTextView in my adapter class like this:

public class JobAdapter extends ArrayAdapter<Job> {
    private final Context context;
    private final ArrayList<Job> jobs;
    private final int layoutResourceId;
    private ExpandableTextView desc = null;
    private Button expand = null;
    private boolean isExpanded = false;

    public JobAdapter(Context context, int layoutResourceId, ArrayList<Job> jobs) {
        super(context, layoutResourceId, jobs);
        this.context = context;
        this.jobs = jobs;
        this.layoutResourceId = layoutResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder = null;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService((Activity.LAYOUT_INFLATER_SERVICE));

        if (view == null) {
            view = inflater.inflate(layoutResourceId, parent, false);

            holder = new ViewHolder();
            holder.title = (TextView)view.findViewById(R.id.tv_jobTitle);
            //holder.description = (ExpandableTextView)view.findViewById(R.id.tv_JobDesc);
            desc = (ExpandableTextView)view.findViewById(R.id.tv_JobDesc);
            //holder.expand = (Button) view.findViewById(R.id.btn_descExpand);
            expand = (Button) view.findViewById(R.id.btn_descExpand);

            view.setTag(holder);
        } else {
            holder = (ViewHolder)view.getTag();
        }

        Job j = jobs.get(position);

        holder.title.setText(j.getJobTitle());
        //holder.description.setText(j.getDescription());
        desc.setText(j.getDescription());
        // set animation duration via code, but preferable in your layout files by using the animation_duration attribute
        desc.setAnimationDuration(1000L);

        // set interpolators for both expanding and collapsing animations
        desc.setInterpolator(new OvershootInterpolator());

        // or set them separately
        desc.setExpandInterpolator(new OvershootInterpolator());
        desc.setCollapseInterpolator(new OvershootInterpolator());

        //when user clicks the expand/collapse button, expand or collapse the description field
        holder.expand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("Expanding Button Clicked!");
                desc.toggle();
                expand.setText(desc.isExpanded() ? "Collapse" : "Expand");
            }
        });

        // listen for expand / collapse events
        desc.setOnExpandListener(new ExpandableTextView.OnExpandListener() {
            @Override
            public void onExpand(final ExpandableTextView view) {
                Log.d("TextView", "ExpandableTextView expanded");
            }

            @Override
            public void onCollapse(final ExpandableTextView view) {
                Log.d("TextView", "ExpandableTextView collapsed");
            }
        });

        return view;
    }

    static class ViewHolder
    {
        TextView title;
        ExpandableTextView description;
        Button expand;
    }
}

I’m not sure what I am missing, am I not able to use the ExpandableTextView in a custom adapter?

Thanks for the help!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Cliffuscommented, Jul 25, 2016

Hi!

thanks for using ExpandabletextView and reporting this issue. I’ll try to reproduce this issue and provide a solution / fix for your problem. In the meantime, can you double check that the length of the job descriptions exceeds the max length of the TextView?

How urgent do you need a solution for this issue?

Thanks again!

0reactions
Cliffuscommented, Aug 4, 2016

you’re welcome! if you need help with any other issues, let me know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android - Expandable TextView with Animation - Stack Overflow
I have a TextView which firstly shows a small portion of a long text. The user can press a "see more" button to...
Read more >
Expandable TextView in Android - GeeksforGeeks
ExpandableTextView is an Android library which allows us to easily create a TextView which can expand/collapse when user clicks on it .we ...
Read more >
Expandable TextView with LayoutTransition. Part 1 - Medium
The first thing I do not like is: when I click during expanding or collapsing each of these animation still keeps going and...
Read more >
Expandable Text View Using Kotlin and Android Studio
Expandable Text View is an android library that allows the users to create the text view which can expand and collapse to read...
Read more >
Android Studio: Expand and Collapse a TextView - YouTube
Make a TextView to Expand and Collapse using a feature of the Android Studio ( ExpandableListView ) and adapting to a TextView.( No...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found