Question

I'm new to android and I'm just learning. I want some help on how to get superscript in ListView in android. For now, I have a TextView which can make it by < sup > tag using Html.fromHtml() function to get e.g. 23. But now I have just start learning to use ListView and don't know exactly how to use it, but < sup > tag doesn't work.

In onCreate I have this:

...
// Create and populate a history list
String[] history = new String[] {};
ArrayList<String> historyList = new ArrayList<String>();
historyList.addAll(Arrays.asList(history));

// Create ArrayAdapter using the history list.
listAdapter = new ArrayAdapter<String>(this, R.layout.history_list, historyList);
// Set the ArrayAdapter as the ListView's adapter.
historyListView.setAdapter(listAdapter);

And in onClick/AsyncTask/onPostExecute I have this:

...
listAdapter.add(outputToHistory);

In history_list.xml I have this:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textIsSelectable="true" >
</TextView>

Thanks

Was it helpful?

Solution

According to this answer for a related question, the tag should work:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("X<sup>2</sup>"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top