Question: In my application, I've `ellipsize`d my `TextView` so that if the text is too large, it'll show `...` at the end using `android:ellipsize="end"`.

e.g.Text `ABCDEFGHIJKLMNOPQRSTUVWXYZ` is shown as `ABCDEFGHIJ...`. But when the text is small, like `ABCDEF` it still shows `...` at the end making the text look like `AB...`. I can not fix the width of the textview since the same textview is used elsewhere with some different width requirements. What should I do to make it work and show `...` only if the text it large enough.

Answer: 
//In your textview 

add the below attributes also

```
android:maxEms="8"
android:singleLine="true"

```

**NOTE:** you can adjust the ems size to how many chars you want to show.
```
 txtvw.setText("The Indian economy is the world's eleventh-largest by nominal GDP and third-largest by purchasing power parity (PPP). " +
                "      Following market-based economic reforms in 1991, India became one of the fastest-growing major economies; " +
                "      it is considered a newly industrialised country. However, it continues to face the challenges of poverty, illiteracy, corruption, malnutrition, and inadequate public healthcare. " +
                "      A nuclear weapons state and a regional power, it has the third-largest standing army in the world and ranks ninth in military expenditure among nations." +
                "      India is a federal constitutional republic governed under a parliamentary system consisting of 28 states and 7 union territories. " +
                "      India is a pluralistic, multilingual, and multiethnic society. " +
                "      It is also home to a diversity of wildlife in a variety of protected habitats.");
        ViewTreeObserver vto = txtvw.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                ViewTreeObserver obs = txtvw.getViewTreeObserver();
                obs.removeGlobalOnLayoutListener(this);
                if(txtvw.getLineCount() > 1){

                    int lineEndIndex = txtvw.getLayout().getLineEnd(1);
                    String text = txtvw.getText().subSequence(0, lineEndIndex-3)+"...";
                    txtvw.setText(text);

                }

            }
        });

```