歡迎選擇我的課程,讓我們一起見證您的進步~~
Tell me about your solution: In fact, the overall item, ImageView and TextView are all implemented by setting the selector. They are android:background, android:src, android:textColor.
You need to pay attention to two points:
Set the selector in android:textColor, and what needs to be implemented is android:color, not android:drawable.
ListView defaults to the entire item getting focus. If the sub-control does not follow, you need to use android:duplicateParentState="true" to let it get focus.
ImageView and TextView both add this attribute:
android:duplicateParentState="true"
If it were me, I would write the logic in getView (maintain a list or something), modify the list when receiving the selection event, and then call notifyDataSetChanged. Because listView itself is designed to cache items, modifying a single itemView will cause many problems.
Provide a new idea for your reference, use the event distribution method dispatchTouchEvent() or onTouchEvent() to handle it. In the problem you described, when the user clicks on the Item, its corresponding parent layout, ImageView, and TextView can be obtained to the distributed event, but do not intercept it in the event method, so that the background and color values ??of different controls can be changed as you like.
IamgeView and textView always have a parent layout, right? Then you set up the click monitoring of this parent layout. If it is monitored, can you modify the image or text?