2016-09-30 65 views
0

我有一个ListView外的按钮和按钮点击(onClickListener)不起作用。我试过android:focus =“false”,android:descendantFocusability =“blocksDescendants”,但我不知道我是否正确使用它。完全没有工作。我是Android的初学者,请帮我修复它。谢谢。在ListView外部定义的按钮不能正常工作

<?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

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

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

请勾选答案是否正确。

+0

按钮正在出现,但它不能识别Click(onClickListener无效)。 – Shreesha

+0

好吧然后发布你的onclicklistener code.So,我可以理解错误的地方。 – EED