Because the included listView cannot meet the project needs, you can implement the Item project of the custom ListView by implementing your own Adapter to inherit ArrayAdapter.
Each item that clicks ListView will not execute the onItemClick method in setOnItemClickListener.
The reason is that there are some subcontrols in the item. By default, click the focus to get and go to the subcontrol, and the click is invalid.
Solution:
Add android:descendantFocusability="blocksDescendants" in the root directory of the item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro xmlns:app="/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:descendantFocusability="blocksDescendants"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp"> <ImageView android: android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/message_oc" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title" android:textSize="25dp" android:layout_marginLeft="15dp"/> <TextView android: android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:text="date" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android: android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textMultiLine" android:text="message" android:textSize="20dp"/> </LinearLayout> </LinearLayout>
This property defines the relationship between the viewGroup and its child controls when a view gets focus.
There are three types of attribute values:
- beforeDescendants: viewgroup will prioritize its subclass controls to get focus
- AfterDescendants: viewgroup only gets focus when its subclass control does not need to get focus
- blocksDescendants: viewgroup will overwrite subclass controls and directly get focus
We use the blocksDescendants property to override the subclass control and get the focus directly.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.