Android TextView text overflow indicator?

I was wondering if there is a way to replace the last three characters of the TextView with "...", but only if the current text overflows the TextView. I have to limit the TextView to 1 line, but sometimes the text is too long, and I would like to show "..." at the end to indicate that the text is longer than shown.

thank

+5
source share
2 answers

, , . , , , (-3 3 ), - :

int MAX_CHARS = 55;  // for example
TextView tv = (TextView) findViewById(R.id.your_text_view_id);
if(tv.getText().toString().length >= MAX_CHARS){
    tv.setText(tv.getText().toString().substring(0,MAX_CHARS) + "...");
}

, , , , , MAX_CHARS. ( )

0

All Articles