Reputation: 519
I want to check the no of lines in my text view from the string I am going to pass to the test view. I have added android:maxLines = "2".... If it exceeds two i need to show/hide a view....How can I achieve this?
Upvotes: 2
Views: 3303
Reputation: 943
I believe the TextView has a method getLineCount which you can use to get the number of lines. You can compare that function's return value with maxLines and show/hide if the limit is reached.
See also: TextView.getLine()
And: TextView - maxLines attribute
Upvotes: 3
Reputation: 11873
Use a thread to count the number of lines,
textView.setText("Text Here");
textView.post(new Runnable() {
@Override
public void run() {
Log.v("Line count: ", textView.getLineCount()+"");
}
});
If you want to limit the number of lines in TextView from xml then use android:maxLines
Upvotes: 5