각 항목에 bg 이미지, textView 및 2 개의 imageView가있는 사용자 정의 LinearLayout이있는 ListView가 있습니다. LiearLayout의 BG 이미지가 텍스트 색상을 변경해야 다른 ListItem은 bg 색상, 눌렀을 때 텍스트 및 이미지 색상을 변경해야합니다.
- : 는 지금은 사용자가 항목을 터치하는 동안, 그 모두가 "를 누르면"상태로 전환하는 것이 필요 항목의
- 모두 ImageViews는
일반적으로 같은 물건을 내 선택이있는 XML 리소스를 사용하여 수행 할 것, 예를 들어 다른 이미지
문제는 눌려진 상태가 자식 뷰 (?)가 아닌 LinearLayout에 의해 감지되므로 배경 이미지 만 변경된다는 것입니다.
OnTouchListener를 사용하여 구현하려고했지만 목록 항목 내부의보기에 안전하게 액세스 할 수 없다는 문제가 발생합니다.
목록 항목의 getView()에서 반환 한보기를 캐싱하여 나중에 이미지와 텍스트 색상을 변경하려고했습니다. 일반적으로 작동하지만 예 : 목록 항목 중 하나에서 다른 활동이 열리면보기가 사라지고 강조 표시된 상태가 무기한 유지됩니다. 디버깅을 시도했는데 디버거를 단계별로 실행하면 올바르게 작동합니다.
또한 cachedView를 재사용하면 아무런 문제가없는 것처럼 보이므로 매번 목록 항목에 새로운보기가 추가됩니다 (비효율적이어야 함).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
android:gravity="center_vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/img_menu_item_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/info" />
<TextView
android:id="@+id/txt_menu_item_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24dp"
android:text="Menu item"
android:textColor="@color/text_dark"
android:layout_marginLeft="5dp" />
<ImageView
android:id="@+id/img_menu_item_arrow"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/arrow" />
</LinearLayout>
Texture의 배경을 컬러에서 drawable으로 변경 한 것을 보았습니다 ... 그렇다면 selector_color_my_button_text의 내용은 무엇입니까? –