Chunlin Zhang
Chunlin Zhang

Reputation: 111

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>

Upvotes: 0

Views: 1312

Answers (2)

Chunlin Zhang
Chunlin Zhang

Reputation: 111

At last,I found scrollview is which I need.Thank you for you reply. Like as:

  <ScrollView>
   <LinearLayout>
   <TextView/>
   <TextView/>
   ...or something else
   <TextView/>
   </LinearLayout>
  </ScrollView>

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006869

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

Upvotes: 2

Related Questions