2016-09-30 35 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