Android的列表视图的问题:不能使用<&的ListView GT; < /&的ListView GT;在布局XML? [英] Android Listview question:can not use <ListView> </ListView> in layout xml?

查看:180
本文介绍了Android的列表视图的问题:不能使用<&的ListView GT; < /&的ListView GT;在布局XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写类似下面的XML一个XML,但总是得到一个异常说
导致由:java.lang.UnsupportedOperationException:
addView(查看,的LayoutParams)不支持适配器视图。
这是说,在布局文件不能使用<&的ListView GT; < /&的ListView GT; ,和
它应该是<的ListView /> 和使用Java code被操纵,是

 <?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/
机器人
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:paddingLeft =8DP
        机器人:paddingRight =8DP>    < ListView的机器人:ID =@ + ID /列表视图
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =FILL_PARENT
              机器人:背景=#00FF00
              机器人:layout_weight =1
              机器人:drawSelectorOnTop =假>    <的TextView
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =FILL_PARENT
              机器人:背景=#000000
              机器人:文字=无数据/>
  < /&的ListView GT;
< / LinearLayout中>


解决方案

您不能把一个的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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆