MainstreamDeveloper00
MainstreamDeveloper00

Reputation: 8556

How can I dynamically change number of lines of the TextView in Android?

I have a TextView in which I have to display a large amount of text, but I don't want to show all the text, only three lines and add a button Click to read more, and after clicking on it all the text must expand. How I can implement this functionality and change the number of lines of the text dynamically?

Upvotes: 2

Views: 2668

Answers (2)

Simon Dorociak
Simon Dorociak

Reputation: 33495

Most likely you are looking for setLines() method. All what you need is to register OnClickListener for Button and perform appropriate action:

t = (TextView) findViewById(R.id.textViewId);
t.setLines(3);

btn.setOnClickListener(new OnClickListener() {          
   @Override
   public void onClick(View v) {
      t.setLines(8);
   }
});

Upvotes: 2

Ahmad
Ahmad

Reputation: 72533

You can use TextView.setMaxLines(...) or TextView.setLines(...).

Upvotes: 0

Related Questions