我似乎有使用ListView自定义样式的问题。“ArrayAdapter需要资源ID是一个TextView”问题
所有的在线搜索(stackOverflow和其他网站)pty多半说: - 创建一个my_style.xml布局文件。 - 在适配器中使用它。
但由于某种原因,这似乎并没有为我工作。 MainAct.java:
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.list_content, items);
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0000DD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
保存为/res/layout/list_content.xml。
如果我使用android.R.layout.simple_list_item_1一切正常,用自己的XML文件,我得到“java.lang.IllegalStateException:ArrayAdapter需要资源ID是一个TextView”。
任何想法?
PS:我已经看了很多其他非常类似的问题/问题,其中包括:
"ArrayAdapter requires the resource ID to be a TextView" xml problems
How to set the text at center in ListView android application?
我有第二次,仍然没有工作......如果我的名单。xml文件包含2个textview我需要将它们全部传递给我的arrayAdapter吗?谢谢 – miatech