[英]setOnItemClickListener() not working on listView of Fragments
I have some issues with handle click's on my ListView element witch contains customized ArrayAdapter of Fragments. 我在ListView元素上的句柄单击有一些问题,其中包含自定义的ArrayAdapter of Fragments。 There is no checkbox anywhere, only Button in Fragment is ImageButton and it already has android:focusable="false".
任何地方都没有复选框,只有Fragment中的Button是ImageButton,并且它已经具有android:focusable =“ false”。 In Layout of ListView I have some FrameLayout's, some Buttons and EditText XML code Below.
在ListView的Layout中,下面有一些FrameLayout,一些Button和EditText XML代码。 Any solutions like android:focusable="false" ,android:focusableInTouchMode = "false" , list.setItemsCanFocus(false).
任何解决方案,例如android:focusable =“ false”,android:focusableInTouchMode =“ false”,list.setItemsCanFocus(false)。 I searched a lot but nothing helps.
我搜索了很多,但没有任何帮助。
Here is main container for listView with Gmap and listView above: 这是上面带有Gmap和listView的listView的主要容器:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.medhigh.mapfragmet.MapsActivity" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginRight="8dp"
android:id="@+id/searchLine">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<EditText
android:layout_marginLeft="16dp"
android:layout_marginRight="42dp"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_weight="1"
android:textColor="@color/black"
android:textSize="18sp"
android:hint=" Start Typing Here"
android:textColorHighlight="@color/colorPrimaryTest"
android:textColorHint="#959595" />
<Button
android:id="@+id/clearEditText"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="50dp"
android:layout_gravity="right|center_vertical"
android:background="@drawable/close"
android:focusable="false"/>
</FrameLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.medhigh.mapfragmet.MapsActivity">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/buttonSwitchToList"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="98dp"
android:layout_marginRight="7dp"
android:background="@drawable/format_list"
android:focusable="false"/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="42dp"
android:layout_marginLeft="42dp"
android:layout_marginBottom="12dp"
android:max="300" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBarProgress"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
tools:context=".search.NameFragment"
android:background="@color/white"
android:id="@+id/layoutList">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<EditText
android:layout_marginLeft="16dp"
android:layout_marginRight="42dp"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editTextList"
android:layout_weight="1"
android:textColor="@color/black"
android:textSize="18sp"
android:hint=" Start Typing Here"
android:textColorHighlight="@color/colorPrimaryTest"
android:textColorHint="#959595" />
<Button
android:id="@+id/clearEditTextList"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="10dp"
android:background="@drawable/close"
android:layout_gravity="end|center_vertical"
android:focusable="false"/>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:clickable="true" />
<Button
android:id="@+id/buttonBackToMap"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="24dp"
android:background="@drawable/map"
android:layout_gravity="end|bottom"
android:focusable="false"/>
</FrameLayout>
</LinearLayout> </FrameLayout>
Here is Fragment of List View: 这是列表视图的片段:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="112dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/imageView2"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="@drawable/news_demo"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Location Name"
android:id="@+id/textViewNewsHeader"
android:textColor="@color/colorPrimaryTest"
android:layout_alignTop="@+id/imageView2"
android:layout_toRightOf="@+id/imageView2"
android:layout_toEndOf="@+id/imageView2" />
<TextView
android:layout_width="wrap_content"
android:lines="4"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="60dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Location description"
android:id="@+id/textViewShortStory"
android:textColor="@color/black"
android:layout_below="@+id/textViewNewsHeader"
android:layout_toRightOf="@+id/imageView2"
android:layout_toEndOf="@+id/imageView2" />
<TextView
android:layout_width="wrap_content"
android:lines="4"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="5"
android:id="@+id/clinicNumber"
android:textColor="@color/colorPrimaryTest"
android:layout_alignParentBottom="true"
android:layout_alignEnd="@+id/imageButton"
android:layout_marginEnd="13dp" />
<ImageButton
android:layout_width="42dp"
android:layout_height="42dp"
android:id="@+id/imageButton"
android:src="@drawable/arrow_right_black"
android:background="@color/white"
android:scaleType="fitXY"
android:layout_marginRight="20dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="false"
/>
</RelativeLayout>
Here is some code from view Container class 这是视图容器类中的一些代码
adapter = new LocationHospitalListFragmentAdapter(getContext(), locationList, R.layout.fragment_search_location_hospital_list);
listView.setAdapter(adapter);
listView.setItemsCanFocus(false);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//show list view layout
Toast.makeText(getActivity().getApplicationContext(),"onItemClick",Toast.LENGTH_SHORT).show();
Log.d("333__","on click");
}
});
将此行添加到ListItem的父级布局中android:descendantFocusability="blocksDescendants"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.