Android ListView侦听器不工作,为什么?
我得到了以下布局:Android ListView侦听器不工作,为什么?,android,listview,android-listview,Android,Listview,Android Listview,我得到了以下布局: <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
<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中,我在inViewCreated方法内将OnItemClickListener附加到我的ListView。我首先获取ListView,设置侦听器,然后添加适配器
目前未收到对我的列表的单击
有人能告诉我为什么吗
非常感谢。简单设置即可
android:focusable ="false"
android:focusableInTouchMode ="false"
对于自定义视图中的所有
UI
视图,它在getView()
方法中膨胀。在附加该侦听器的位置张贴代码try OnItemSelectedListener(),我想这是因为我意外插入了安卓:phoneNumber=“true”。现在一切都正常了。请您也显示一下您的适配器代码好吗?