0

當我點擊任何列表項沒有任何反應,有人可以請幫助或告訴我問題在哪裏......?在列表視圖中的點擊項不起作用

這裏是我的列表視圖:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    tools:context=".defineBybeldbAlles"> 


    <ListView 
     android:id="@+id/BybelHoofstukListView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#ff303030" 
     android:dividerHeight="1dp" 
     android:layout_marginTop="5dp" 
     android:choiceMode="singleChoice" /> 
</RelativeLayout> 

這裏是我的ListView項:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:descendantFocusability="blocksDescendants" 
    android:layout_height="match_parent"> 

    <LinearLayout 
      android:id="@+id/customButtonLayout" 
      android:layout_height="50dp" 
      style="@android:style/Widget.Button" 
      android:focusable="false" 
      android:layout_width="200dp"> 

      <! hoofstuk_id is hidden and is only for reference > 
      <TextView 
       android:text="id" 
       android:id="@+id/hoofstuk_id" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="gone" 
       > 
      </TextView> 

      <TextView 
       android:textColor="#000" 
       android:text="nommer" 
       android:layout_height="wrap_content" 
       android:id="@+id/custom_row_hoofstuktext" 
       android:layout_width="wrap_content" 
       android:layout_marginLeft="10dp"> 
      </TextView> 

     </LinearLayout> 

    </LinearLayout> 

這是我在活動OnItemclicklistener:

listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 

@Override 
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){ 

//on selecting a hoofstk 
//BybelActivityVers will be launched to show verse inside 

Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class); 

//send hoofstuk_id to VersActivity to get verse under that book 

String hoofstuk_id_na_vers =((TextView)view.findViewById(R.id.hoofstuk_id)).getText().toString(); 
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers); 

startActivity(hoofstukIntent); 
} 
}); 

伊夫看着幾個其他的解決方案,但沒有我的情況下工作,我加入這個代碼,但它並沒有區別,當我使用與否:

android:focusable="false" 

android:focusableInTouchMode="false" 

android:descendantFocusability="blocksDescendants" 
+0

請發佈您的適配器類 –

+0

您是否收到任何錯誤?或者你是否嘗試調試並確定它是否進入方法? – Meenal

+0

刪除這些_android:focusable =「false」 android:focusableInTouchMode =「false」 android:descendantFocusability =「blocksDescendants」_。無需使用它 – Piyush

回答

0

我刪除

android:focusable="false" 
android:focusableInTouchMode="false" 
android:descendantFocusability="blocksDescendants" 

,然後應用

android:clickable="false" 

它沒有工作,但摸索之後,我發現,

android:clickable="false" 
android:focusable="false" 

結合的伎倆!

這適用於列表查看項目之後LinearLayout

我測試過,並且可以確認它也適用於Gridview。

0

使用適配器視圖在這裏得到adpater項目的意見,你應該使用找到TextView的

​​
1

YOUT列表項中奪取的焦點。設置爲低於線的LinearLayout標籤在my Listview Item xml文件

android:clickable="false" 

你的意圖將火沒有采取重點和正常工作我ahve檢查的話...讓我知道一旦其作品你...

+0

我刪除了'android:focusable =「false」 android:focusableInTouchMode =「false」 android:descendantFocusability =「blocksDescendants」'然後應用你的代碼,它沒有工作,所以我把android: focusable =「false」,它工作。非常感謝你! – FDupie

+0

很高興幫助你... –

0

這裏是您的解決方案:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    tools:context=".defineBybeldbAlles"> 

    <ListView 
     android:id="@+id/BybelHoofstukListView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#ff303030" 
     android:dividerHeight="1dp" 
     android:layout_marginTop="5dp"/> 
</RelativeLayout> 

在您的列表視圖項,你必須讓這改變:

<LinearLayout 
     android:id="@+id/customButtonLayout" 
     android:layout_height="50dp" 
     style="@android:style/Widget.Button" 
     android:layout_width="200dp"> 

     <! hoofstuk_id is hidden and is only for reference > 
     <TextView 
      android:text="id" 
      android:id="@+id/hoofstuk_id" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="gone" 
      > 
     </TextView> 

     <TextView 
      android:textColor="#000" 
      android:text="nommer" 
      android:layout_height="wrap_content" 
      android:id="@+id/custom_row_hoofstuktext" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp"> 
     </TextView> 

    </LinearLayout> 

</LinearLayout> 

這應該解決您的問題,如果不是正好碰上評論這個答案。之後,你將開始獲得ListView的OnItemClick()事件。