Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

Android Listview question:can not use <ListView> </ListView> in layout xml?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot put a TextView inside of a ListView this way. You need to associate a ListAdapter object with the ListView.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...