Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:35:28+00:00 2026-06-16T21:35:28+00:00

I have a listView, one component of the row is a TextView. By default,

  • 0

I have a listView, one component of the row is a TextView. By default, I wish to show only 2 rows of text in the TextView. But if the user taps on the TextView I wanted to the textView to expand in context.

I actually have this portion working, but I want to have a more content indicator :

enter image description here

My current implementation (Below) has it’s own issues w/ not collapsing if the list view is scrolled, but I will handle that by storing the values for each cursor record in some collection..

I tried using chatBubble.getLineCount() but that returns zero initially b/c it has not gone through onLayout (from my understanding).

I only wish to show it if there is more than 2 lines of content.

I figure my solution will be creating my own implementation of TextView which can handle some of my requirements, but not sure if anyone has any examples I can look at.. (Or other suggestions).

   <RelativeLayout
        android:id="@+id/linear_layout_row_three"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linear_layout_row_two"
        android:layout_toRightOf="@+id/munzeeQuickContact"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/chat_bubble"
            android:clickable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="2"
            android:background="@drawable/chat_bubble"
            android:text="I went looking for this particular token on a rainy day, and I was unable to locate it due to the bad weather, next time please leave an um I went looking for this particular munzee on a rainy day, and I was unable to locate it due to the bad weather, next time please leave an um" />
        <ImageView 
            android:id="@+id/minimize_maximize"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/chat_bubble"
            android:layout_alignRight="@id/chat_bubble"
            android:visibility="gone"
            android:src="@android:drawable/ic_menu_more"/>
    </RelativeLayout>

Here is some of the source I currently have :

final TextView chatBubble = (TextView) view.getTag(R.id.chat_bubble);
        final ViewGroup expandableContainer = (ViewGroup) view.getTag(R.id.linear_layout_row_three);
        final ImageView minimizeMaximize = (ImageView) view.getTag(R.id.minimize_maximize);
        chatBubble.setOnClickListener(

                new View.OnClickListener() {
                    boolean isExpanded = false;
                    int lastHeight = 0;
                    // This is for the auto expanding text view
                    @Override
                    public void onClick(View v) {
                        if (isExpanded) {
                            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) expandableContainer
                                    .getLayoutParams();

                            params.height = lastHeight;
                            chatBubble.setMaxLines(2);

                            expandableContainer.setLayoutParams(params);
                            expandableContainer.invalidate();
                            minimizeMaximize.setVisibility(View.VISIBLE);
                        } else {
                            lastHeight = expandableContainer.getHeight();

                            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) expandableContainer
                                    .getLayoutParams();

                            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                            chatBubble.setMaxLines(99);

                            expandableContainer.setLayoutParams(params);
                            expandableContainer.invalidate();
                            minimizeMaximize.setVisibility(View.VISIBLE);
                        }

                        isExpanded = !isExpanded;

                    }
                });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:35:29+00:00Added an answer on June 16, 2026 at 9:35 pm

    I figure my solution will be creating my own implementation of
    TextView which can handle some of my requirements, but not sure if
    anyone has any examples I can look at..

    Have a look at the class below:

    public class LimitedTextView extends TextView {
    
        private boolean mStatus;
    
        public LimitedTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            Paint p = getPaint();
            String s = getText().toString();
            if (s != null && !s.equals("")) {
                int m = (int) p.measureText(s);
                if (m < getMeasuredWidth() * 2) {
                    modifyParent(true);
                } else {
                    modifyParent(false);
                }
            }
        }
    
        private void modifyParent(boolean how) {
            RelativeLayout rl = (RelativeLayout) getParent();
            rl.findViewById(R.id.minimize_maximize).setVisibility(
                    how ? View.GONE : View.VISIBLE);
            if (mStatus) {
                setMaxLines(40); // arbitrary number, set it as high as possible
            } else {
                setMaxLines(2);
            }
        }
    
        public void storeCurrentStatus(boolean status) {
            mStatus = status;
        }
    
    }
    

    The LimitedTextView will measure its text using its own Paint object and test it against the measured width. If it fits on the two allowed rows it will hide the ImageView, otherwise it will show it. It also stores the current status of row(expanded/not-expanded) and increases or decreases the maximum number of lines to obtain the proper appearance.
    In the getView method of the adapter you would:

    • set the text
    • set the status from a boolean array according to a position(this is also required to keep the rows in order as you scroll the list):

      textView.storeCurrentStatus(mStatus[position])

    • set the OnClickListener on the LimitedTextView itself and from there update the status:

      mStatus[(Integer) v.getTag()] = !mStatus[(Integer) v.getTag()];
      notifyDataSetChanged();
      
    • based on the same mStatus boolean array you’ll probably change the drawable of the ImageView, to show a different one depending on if the TextView is expanded or not

    I manually wrote it, so there could be some mistakes I’m missing right now, take it as an idea. The LimitedTextView could be improved as in performance, I also don’t know how well it would behave if you want to animate expanding the text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one SubjectTabActivity and i need to show listview on this activity. But
I have a listview with one textview and a button in each row. Button
I have ListView which as one TextView in each Row. and im discovering some
I have listview having customized some textview and one imageview. When I long click
I have a ListView with one TextView. List view is populated from a string
I have a listview which one of the is binding my user's photo image.
I have one listview.which contain one image ,text and one button .i had creted
Hi I have a Custom ListView with one ImageView and TextView . Here is
I have a ListView and one of the rows (the first one) is a
My activity implements OnTouchListener and it have one ListView inside it. When user touch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.