Android displaying text in TextView
<p>Hi all,</p>

<p>I'm banging my head with a problem that seems intractable to me (perhaps my ignorance x).</p>

<p>I have a <code>TextView</code> in which a string when I write, I calculate the space available and if necessary I reduce the font size to a minimum size set, then add a line and keep writing.</p>

<p>PROBLEM:</p>

<p>Writing strings of buttons 2 and 3, display the lines of the <code>TextView</code> are filled in correctly: the first line is complete and the rest of the string goes on the second line.
ES.:</p>

<pre><code>56688+(555556565555566
555555

56688x(555556565555566
555555
</code></pre>

<p>Writing strings of buttons 1 and 4, show the lines of the <code>TextView</code> are filled incorrectly:
the first line is filled up to the '/' or '-' remained largely empty, and the text after the character is on the second line.
ES.:</p>

<pre><code>                56688/
(555556565555566555555

                56688-
(555556565555566555555
</code></pre>

<p>The intended behavior is that of the strings of the buttons 2 and 3.</p>

<p>I can not understand why it behaves abnormally in the presence of the characters '/' and '-', and how to remedy this anomaly.</p>

<p>I enclose code:</p>

<p>In the file "activity_main.xml" I have a custom component that I report below:</p>

<pre><code>&lt;LinearLayout android:id="@+id/mainLayout" 
android:layout_width="fill_parent"         
android:layout_height="wrap_content" 
androidrientation="vertical"  
android:layout_alignParentTop="true"&gt;

&lt;com.example.component.NumTextView
 android:id="@+id/textViewInput"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:focusable="true"
 android:gravity="right"
 android:maxHeight="64dp"
 android:minHeight="64dp"
 app:lines="1"
 app:maxLines="3"
 app:mintextsize="16"
 app:maxtextsize="48"
 androidadding="0dp"
 android:scrollbars="vertical"
 android:singleLine="false" android:text="" /&gt;

&lt;View android:layout_width="fill_parent" 
 android:layout_height="1dp"  
 android:background="#000000" /&gt;
</code></pre>

<p>In the class "NumTextView" that inherits from "TextView" I have the following code:</p>

<pre><code>private void refitText(String text, int textWidth)
{
 float trySize = 23;
if( textWidth &gt; 0 )
{
int lineCount = this.getLineCount();
this.setLines(lineCount + 1);
this.setVerticalScrollBarEnabled(true);
this.setMovementMethod(ScrollingMovementMethod.get Instance());
this.setTextSize(trySize);
}
}


@Override
protected void onTextChanged(final CharSequence text, final int start, final int before, final int after)
{
refitText( text.toString(), this.getWidth() );
}
</code></pre>

<p>Finally, in "MainActivity" I have the following code:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textInput = (NumTextView) findViewById(R.id.textViewInput);
}

public void onClick1(View v)
{
String stringa ="56688-(555556565555566555555";
textInput.setText(stringa);
}

public void onClick2(View v)
{
String stringa ="56688+(555556565555566555555";
textInput.setText(stringa);
}

public void onClick3(View v)
{
String stringa ="56688x(555556565555566555555";
textInput.setText(stringa);
}

public void onClick4(View v)
{
String stringa ="56688/(555556565555566555555";
textInput.setText(stringa);
}
</code></pre>
