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()事件。