【问题标题】:Superscript/subscript in ListView (android)ListView 中的上标/下标 (android)
【发布时间】:2013-04-14 04:48:56
【问题描述】:

我是 android 新手,我只是在学习。 我想要一些关于如何在 android 的 ListView 中获取上标的帮助。 现在,我有一个 TextView 可以通过 标签使用 Html.fromHtml() 函数来获取例如23。 但是现在刚开始学习使用ListView,不知道具体怎么用,但是标签不起作用。

在 onCreate 我有这个:

...
// 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);

在 onClick/AsyncTask/onPostExecute 我有这个:

...
listAdapter.add(outputToHistory);

在 history_list.xml 我有这个:

<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>

谢谢

【问题讨论】:

标签: android html listview superscript


【解决方案1】:

根据this answer的相关问题, 标签应该可以工作:

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

【讨论】:

  • 这适用于 TextView,但如何在 ListView 中处理它?
  • 完全相同 - 当您在适配器中填充 ListView 项目时,请像示例中一样调用 setText。您可能必须为此创建一个自定义适配器,或者可能使用 ArrayAdapter,并提供使用 Html.fromHtml("...") 创建的 Spannables 数组
  • 完美!非常感谢:)
猜你喜欢
  • 2013-03-26
  • 2012-11-15
  • 2011-04-02
  • 2013-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多