在ListView外部定义的按钮不起作用

时间:2016-09-30 06:15:23

标签: android listview

我在ListView之外有一个Button,按钮单击(onClickListener)不起作用。我试过android:focus =“false”,android:descendantFocusability =“blocksDescendants”,但我不知道我是否正确使用它。完全没有用。我是android的初学者,请帮我解决它。谢谢。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false">

<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/b1"/>

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listView1"/>
</LinearLayout>

1 个答案:

答案 0 :(得分:1)

您设置的所有内容都是正确的。但只需更改layout_width和layout_height属性即可。可能是按钮返回列表视图。所以这就是它没有出现的原因。 尝试更改xml中的listview内容,如下所示:

<ListView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/listView1"/>

如果答案正确,请勾选答案。

相关问题