0

Когда я нажимаю на любой элемент списка, ничего не происходит, может кто-то, пожалуйста, помогите или скажите мне, где проблема ...?Нажмите элемент в спискеview не работает

Вот мой ListView:

<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 Item:

<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); 
} 
}); 

Ive посмотрел на несколько других решений, но ничего не работает в моем случае, я добавил этот код, но это не имеет никакого значения, когда я использую его или нет:

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

Используйте AdapterView получить adpater представлений элементов здесь вы должны использовать родитель найти TextView

listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       //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)parent.findViewById(R.id.hoofstuk_id)).getText().toString(); 
       hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers); 
       startActivity(hoofstukIntent); 
      } 
     }); 
1

Yout элемент списка берет фокус. Установите ниже линии в LinearLayout Tag в my Listview Item xml файл

android:clickable="false" 

Ваше намерение будет стрелять, не принимая фокус и работать правильно, я ahve проверил это ... Дайте мне знать, когда его работы для вас ...

+0

я удалил 'андроид: фокусируемый =«ложь» андроид: focusableInTouchMode =«ложь» андроид: descendantFocusability =«blocksDescendants»' а затем применяется код, оно не работает, так что я положил обратно андроид: 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> 

Это должно решить вопрос, если не просто ударил комментарий по этому ответу. После этого вы начнете получать OnItemClick() событие listview.