Reputation: 3437
I would like to use an exponent like this programmatically in a textview:
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
Reputation: 686
I this u have to use like this.
your_textview.setText(Html.fromHtml("m<sup>3</sup>"));
Or
Upvotes: 0
Reputation: 3402
Try Html.fromHtml instead. Simple and precise:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("m<sup>3</sup>"));
Upvotes: 1