일부 ListItem이있는 ListFragment가 있습니다. 하나의 ListItem에서 나는 몇몇 Views와 또한 CardViews를 가진 RecyclerView를 가지고있다. 에서 CardView는 ImageView입니다.RecyclerView에서 부모 ListFragment 또는 ListAdapter로 click 이벤트 보내기
RecyclerView를 사용하여 사진을 찍고 싶은데 사진을 스크롤하고 싶습니다. 두 손가락 제스처로 사진을 확대하고 싶습니다. (누군가가 단계 튜토리얼에 따라 좋은 단계를 알고 있다면 좋을 것이다.) 그러나 나는 또한 그림을 클릭하고 longclick하고 싶다. 내 ListArrayAdapter 또는 내 ListFragment에서 클릭 및 longclick이 필요합니다. Parent click event not firing when recyclerview clicked
그러나 클릭이 어댑터 또는 ListFragment에 도달하지 않습니다
나는 그렇게이 허용 대답을 발견했다.java.lang.NullPointerException이 : 인터페이스 메소드를 호출하는 시도 '부울 android.view.ViewParent.showContextMenuForChild 나는 LongClick과 좀 더 플레이하면 CardView가 performLongClick를 호출하고이 NullPointerException이 끝나는 때문에 앱 충돌 로이드에서 android.view.View.performLongClickInternal (View.java:6280)에서 android.view.View.showContextMenu에서 널 객체 참조 에 (android.view.View에서) '(View.java:6346) .view.View.performLongClick (View.java:6234)
그래서 모든 것이 잘 작동해야합니까?
이
은 rowlayout입니다 - 조금 수축 :<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="ListFragment"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="left|center_vertical"
android:layout_marginLeft="5dp"
android:minHeight="30dp"
android:orientation="vertical"
android:layout_toLeftOf="@+id/icon"
>
<RelativeLayout
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="wrap_content"
android:layout_height="350dp"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
나는 myLayout-보기 위해와 ListAdapter의 myRecyclerView-보기 위해 OnClickListener를 (온 클릭 (보기))이있다. ListFragment에는 내 onListItemClick 메서드에도 중단 점이 있습니다. 그러나 아무 일도 일어나지 않습니다.
CardView 레이아웃 :
<com.package.MyCardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp"
android:descendantFocusability="blocksDescendants"
>
<ImageView android:id="@+id/picture"
android:src="@drawable/picture_empty"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="0dp"
android:padding="0dp"
android:adjustViewBounds="true"
android:visibility="invisible"
xmlns:android="http://schemas.android.com/apk/res/android" />
</com.package.MyCardView>
당신은 위의 링크에서 허용 대답에서 볼 수 MyCardView의 소스입니다. Initialize()가 호출되었고 ImageView/CardView에서 short를 터치하면 onInterceptTouchEvent()가 호출되었지만 ACTION_DOWN 이벤트가 발생하고 onDown()과 onLongPress()가 호출되었습니다.
일부 레이아웃 코드를 추가했다. 그 밖의 무엇이 필요합니까? 나는 그들 중 많은 것을 가지고있다. :) – chrispi