Android的列表视图的问题:不能使用&lt;&的ListView GT; &LT; /&的ListView GT;在布局XML? [英] Android Listview question:can not use <ListView> </ListView> in layout xml?
问题描述
我试着写类似下面的XML一个XML,但总是得到一个异常说
导致由:java.lang.UnsupportedOperationException:
addView(查看,的LayoutParams)不支持适配器视图。
这是说,在布局文件不能使用&LT;&的ListView GT; &LT; /&的ListView GT;
,和
它应该是&LT;的ListView /&GT;
和使用Java code被操纵,是
&LT;?XML版本=1.0编码=UTF-8&GT?;&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/
机器人
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:paddingLeft =8DP
机器人:paddingRight =8DP&GT; &LT; ListView的机器人:ID =@ + ID /列表视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=#00FF00
机器人:layout_weight =1
机器人:drawSelectorOnTop =假&GT; &LT;的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=#000000
机器人:文字=无数据/&GT;
&LT; /&的ListView GT;
&LT; / LinearLayout中&GT;
您不能把一个的TextView
的内部的ListView
这种方式。你需要用 ListAdapter
对象关联的的ListView
。
I try to write a xml like below xml,but always get an exception say
that"Caused by: java.lang.UnsupportedOperationException:
addView(View,LayoutParams) is not supported in Adapterview".
It is say that in layout xml can not use <ListView> </ListView>
,and
it should be <ListView />
and be manipulated using java code,is it?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:text="No data"/>
</ListView>
</LinearLayout>
You cannot put a TextView
inside of a ListView
this way. You need to associate a ListAdapter
object with the ListView
.
这篇关于Android的列表视图的问题:不能使用&lt;&的ListView GT; &LT; /&的ListView GT;在布局XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!