Reputation: 35
I am using
private final static String MICRO = "&#x3BC";
and
private final static String SQUARE = "&#xB2";
to display ms^2 and MICRO symbol as
case Sensor.TYPE_ACCELEROMETER:
units = "m/s" + SQUARE;
case Sensor.TYPE_MAGNETIC_FIELD:
units = MICRO + "T";
But its returning same values. i.e MICRO = "&#x3BC"; and SQUARE = "&#xB2";
on App. Is there an alternative way to display these units?
Upvotes: 1
Views: 1308
Reputation: 4656
Here's another options - use HTML.
First, create XML strings
<string name="ms"><![CDATA[%1$s m/s<sup><small><small>2</small></small><sup>]]></string>
<string name="ut"><![CDATA[%1$s μT]]></string>
Now, use them in your Java:
TextView txtMs = findViewById(R.id.txtMs);
String ms2 = String.format(getResources().getString(R.string.ms), "2.8");
txtMs.setText(Html.fromHtml(ms2));
TextView txtUt = findViewById(R.id.txtUt);
String ut = String.format(getResources().getString(R.string.ut), "2000.0");
txtUt.setText(Html.fromHtml(ut));
Result:
Upvotes: 0
Reputation: 35
Just Changing MICRO = "&#x3BC"; to MICRO = "μ";
and
SQUARE = "&#xB2"; to SQUARE = "²";
works
Upvotes: 2