I have a combination of strings and depending on the maximum number of characters that will fit on the button I want to adapt the length of the individual strings. How do I get the max number of characters on a button:
Button foo=(Button)findViewById(R.id.foobutton);
String a="longtext";
String b="longtext";
String c="longtext";
foo.setText(a+b+c);
But if a+b+c won't fit, I want to cut off for example String b.
I tried the following, but it gives more characters than actually fit:
int maxpix=foo.getLayout().getEllipsizedWidth();
float textlengthinpix=foo.getPaint().measureText(a+b+c);
float pixperchar=textlengthinpix/((a+b+c).length());
int maxcharsinview=(int) (maxchars/pixperchar);