0

I am new in android and I am writing code for counter. I am showing the increasing count in the text view. If there are four digits in the text view, it shows normally, but when counter value is greater than 9999, text view showing 5 digits. Problem is that these five digits are not in single line. I want to know if there is any function or method by which text size in the text view can be change dynamically. Is there any if condition to be used like

If(counter > 9999){ change text size to any value, less than the previous value given in the xml file. } Any help will be highly appreciated

Momin Khan
  • 147
  • 10
  • http://stackoverflow.com/questions/2617266/how-to-adjust-text-font-size-to-fit-textview – David Oct 20 '16 at 07:51
  • https://github.com/grantland/android-autofittextview – Tim Oct 20 '16 at 07:51
  • as i said Tim I am new. I am not getting where to put my this code. counterDisplay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { increment++; editor.putInt("number", increment); editor.apply(); display(); } }); – Momin Khan Oct 20 '16 at 08:01
  • 1
    @Momin Khan Would like to give you a suggestion. Instead of changing the font size dynamically, try to adjust the TextView from the xml so that it will take any number of digits. If you could post your xml here, it would be helpful. – vidulaJ Oct 20 '16 at 08:27
  • It would be great if you could provide the whole xml or at least with a parent layout and given your TextView I suggest you to reduce the text size. – vidulaJ Oct 20 '16 at 09:21
  • @vidulaJ thank you so much for your consideration... :) but i have found a simple solution by felix...you can see it on this page.. – Momin Khan Oct 20 '16 at 09:37
  • No problem. I'll see that. – vidulaJ Oct 20 '16 at 09:39

1 Answers1

1

Warning: This is pseudocode!

TextView myTextView = (TextView) findViewById(R.id.mytextviewID);


if(myTextView.getText() < 9999)
{
  myTextView.setTextSize(DpValueAsInt);
}
Felix
  • 824
  • 8
  • 21
  • thank you Felix....so just save the whole lot of time (Y) its a shortcut and reliable method... but i would suggest seniors to use that library of AutoFitTextView. well this approach is best for me :) – Momin Khan Oct 20 '16 at 09:26
  • As a senior developer you wouldn't want to have many third party libraries in your code. So you would write a proper solution on your own. – Felix Oct 20 '16 at 09:43