i'm trying implement d-pad navigation in app. added android:focusable="true" recyclerview item, , android:descendantfocusability="afterdescendants" recyclerview. can navigate through items d-pad , down buttons, when press on center button, nothing happens. how can launch onitemclick method when center button pressed?
recyclerview item layout:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout 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:id="@+id/row_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:layout_marginbottom="8dp" android:layout_margin="8dp" android:elevation="2dp" android:focusable="true"> <textview android:id="@+id/row_item_shortstory" android:layout_marginend="16dp" android:layout_marginright="16dp" app:layout_constraintright_torightof="parent" tools:text="Описание" app:layout_constraintbottom_tobottomof="parent" android:layout_height="wrap_content" android:textsize="18sp" android:layout_width="0dp" android:layout_marginstart="16dp" app:layout_constraintleft_torightof="@+id/row_item_poster" android:layout_marginleft="16dp" android:layout_marginbottom="16dp" android:layout_margintop="16dp" app:layout_constrainttop_tobottomof="@+id/row_item_star_rating" app:layout_constraintvertical_bias="0.0"/> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" app:srccompat="@drawable/ic_action_rating" android:id="@+id/row_item_star_rating" app:layout_constraintright_toleftof="@+id/row_item_rating" app:layout_constrainttop_tobottomof="@+id/row_item_year"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_item_rating" app:layout_constraintright_torightof="parent" tools:text="Рейтинг" android:layout_marginend="16dp" android:layout_marginright="16dp" android:layout_margintop="7dp" app:layout_constrainttop_tobottomof="@+id/row_item_year"/> </android.support.constraint.constraintlayout>
i tried add android:onclick="onitemclick" recyclerview item, doesn't work, because recyclerview works custom itemtouchlistener
class recycleritemclicklistener extends recyclerview.simpleonitemtouchlistener { private static final string tag = "recycleritemclicklisten"; // need define interface can use call on interface onrecyclerclicklistener { void onitemclick(view view, int position); void onitemlongclick(view view, int position); } private final onrecyclerclicklistener mlistener; private final gesturedetectorcompat mgesturedetector; public recycleritemclicklistener(context context, final recyclerview recyclerview, onrecyclerclicklistener listener) { // need context gesturedetector work //need reference recyclerview we're detecting taps on mlistener = listener; mgesturedetector = new gesturedetectorcompat(context, new gesturedetector.simpleongesturelistener() { @override public boolean ondown(motionevent event) { // triggers first both single tap , long press return true; } @override public void onlongpress(motionevent e) { log.d(tag, "onlongpress: starts"); view childview = recyclerview.findchildviewunder(e.getx(), e.gety()); if (childview != null && mlistener != null) { // log.d(tag, "onlongpress: calling listener .omitemlongclick"); mlistener.onitemlongclick(childview, recyclerview.getchildadapterposition(childview)); } } @override public boolean onsingletapup(motionevent e) { log.d(tag, "onsingletapup: starts"); view childview = recyclerview.findchildviewunder(e.getx(), e.gety()); // check see view underneath using coordinates on screen tapped // , return view found if (childview != null && mlistener != null) { // log.d(tag, "onsingletapup: calling listener .onitemclick"); mlistener.onitemclick(childview, recyclerview.getchildadapterposition(childview)); // calls onitemclick mainactivity } // return true return true; } }); } @override public boolean onintercepttouchevent(recyclerview rv, motionevent e) { //method called whenever sort of touch happens (tap, doubletap, swipe etc.) if (mgesturedetector != null) { boolean result = mgesturedetector.ontouchevent(e); return result; } else { return false; } } }
so tried add setonkeylistener
recyclerview in answer - https://stackoverflow.com/a/32921945/7478869 doesn't change anything.
did have similar situations? how make center button work?
Comments
Post a Comment