2015-05-20 10 views
0

я получил следующую структуру:ListView onItemClickListener не работает, почему?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.iav.viraprecorder.ServerListFragment" 
    android:paddingTop="@dimen/recording_details_padding_top_bottom" 
    android:paddingBottom="@dimen/recording_details_padding_top_bottom" 
    android:paddingLeft="@dimen/recording_details_padding_left_right" 
    android:paddingRight="@dimen/recording_details_padding_left_right"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/next" 
     android:id="@+id/server_list_next_button" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:enabled="false"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/list_available_servers" 
     android:id="@+id/server_list_heading"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/server_list_hint" 
     android:id="@+id/server_list_hint" 
     android:layout_below="@+id/server_list_heading" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"/> 

    <ListView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/server_list_view" 
     android:layout_below="@+id/server_list_hint" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_above="@id/server_list_next_button" 
     android:choiceMode="singleChoice" 
     android:background="?android:attr/activatedBackgroundIndicator"/> 

</RelativeLayout> 

Элементы ListView получили следующий стиль:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Type: Anything" 
     android:id="@+id/type"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Description: ..." 
     android:id="@+id/description"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="API-Level: 2" 
     android:id="@+id/api_level"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Generated on: 10.08.2013" 
     android:id="@+id/generated_date" 
     android:phoneNumber="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Address: 192.168.111.112:32001" 
     android:id="@+id/address"/> 

</LinearLayout> 

В моей ServerListFragment.java я прикрепить OnItemClickListener к моему ListView внутри метода inViewCreated , Сначала я получаю ListView, устанавливаю слушатель, а затем добавляю адаптер.

В настоящее время нажмите на мой список не принимаются.

Может ли кто-нибудь сказать мне, почему?

Большое спасибо.

+1

Оставьте свой код слишком –

+1

Отправьте код, в который вы прикрепляете этот прослушиватель – MikeKeepsOnShine

+0

попробуйте OnItemSelectedListener() – Prakhar

ответ

0

Просто установите

android:focusable ="false" 
android:focusableInTouchMode ="false" 

для всех UI представлений в настраиваемое представление, которое раздувания в getView() методе.