dabo248
dabo248

Reputation: 3437

How to write an exponent into a textview?

I would like to use an exponent like this programmatically in a textview:

example image for m^3

Is it possible, and if yes, how?

Edit: got it, thanks for helping!!

SpannableStringBuilder dataset = new SpannableStringBuilder(dataset2[position] + " m3");

dataset.setSpan(new SuperscriptSpan(), dataset2[position].length() + 2, dataset2[position].length() + 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
dataset.setSpan(new RelativeSizeSpan(0.75f), dataset2[position].length() + 2, dataset2[position].length() + 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

holder.mTextView2.setText(dataset);

Upvotes: 1

Views: 3834

Answers (2)

Jaydip
Jaydip

Reputation: 686

I this u have to use like this.

your_textview.setText(Html.fromHtml("m<sup>3</sup>"));

Or

Use this too

Upvotes: 0

Jithin Sunny
Jithin Sunny

Reputation: 3402

Try Html.fromHtml instead. Simple and precise:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("m<sup>3</sup>"));

Upvotes: 1

Related Questions