Android layout 我无法将按钮添加到线性布局

Android layout 我无法将按钮添加到线性布局,android-layout,android-listview,Android Layout,Android Listview,我有一个listActivity,它通过适配器显示从web获取的xml提要以及布局文件activity_list_feed.xml: `<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" android:transc

我有一个listActivity,它通过适配器显示从web获取的xml提要以及布局文件activity_list_feed.xml:

`<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    android:transcriptMode="normal"
    />`
``
在图形编辑器中,我无法将按钮拖动到此布局中,当我尝试根据此文件硬编码时:

`<?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" >
<Button
    android:id="@+id/addBtn"
    android:text="Add New Item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="addItems"/>
<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    android:transcriptMode="normal"
    />
</LinearLayout>`
`
`
我收到一条编译错误消息:

java.lang.ClassCastException:android.widget.LinearLayout无法强制转换为android.widget.TextView


我如何才能在列表顶部添加按钮,因为我想刷新pull。谢谢。

您提供的代码实际上在Android Studio中的当前状态下工作:

确保在java代码中引用了正确的项。确保将总体布局设置为该布局,然后执行
findviewbyd(R.layout.addBtn)


另外,尝试将IDE中的Android版本更改为22(我在图片右上角设置了它)。这可能会解决你的错误

我成功地在编辑器中添加了按钮,并且没有按照您的图片设置为API 22。然而,程序仍然没有编译

消息错误“ArrayAdapter要求资源ID为TextView”意味着我没有为适配器提供正确的参数

根据这一回答: 看来构造函数的选择很重要,因为我想在视图中添加一个按钮,所以我必须使用带有4个参数的构造函数(附加参数是视图的id):

使用这个构造函数解决了这个问题