2012-01-30 127 views
0

我正在追踪这个啧啧 http://developer.android.com/resources/tutorials/views/hello-listview.html的Android,添加扩展以XML布局

,我想知道我怎样才能添加customView到main.xml中的布局

的XML:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/main_title" /> 

    <com.package.profile.view.HelloListView 
     android:id="@+id/listView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 

的HelloListView类包是com.package.profile.view

我得到错误 01-30 16:00:38.875:E /和roidRuntime(27614):java.lang.RuntimeException:无法启动活动ComponentInfo {com.package.profile/com.package.profile.ListDemoActivity}:android.view.InflateException:二进制XML文件行#12:Class不是视图com.package.profile.view.HelloListView

谢谢。

+0

请分享你的代码为“HelloListView.java”似乎它不是从ListView或View扩展 – Arslan 2012-01-30 14:19:08

回答

0

本教程不延长View,而是一个Activity,更精确地ListActivity。你的主要布局应该是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/main_title" /> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 
</FrameLayout>