android - Click listener on a recylerview itself -


i trying set onclick listener on recyclerview (not items) it's not firing!

i have rv inside cardview, if matters! searched internet; nothing helped!

xml code:

<relativelayout     android:layout_width="match_parent"     android:layout_height="wrap_content">      <textview         android:id="@+id/text_view_entry_status"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textcolor="@color/accent"         android:background="@color/green_700"         android:paddingtop="2dp"         android:paddingbottom="2dp"         android:paddingstart="8dp"         android:textstyle="bold"         android:paddingend="8dp"         android:layout_alignparentend="true"         tools:text="entry status label text" />      <view         android:id="@+id/view_click_interceptor"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/text_view_entry_status"         android:layout_above="@+id/relative_layout_delete_entry"         android:layout_margintop="16dp"         android:background="@android:color/transparent" />       <android.support.v7.widget.recyclerview         android:id="@+id/recycler_view_entry_fields"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/text_view_entry_status"         android:layout_margintop="16dp" />   <relativelayout     android:id="@+id/relative_layout_delete_entry"     android:layout_width="48dp"     android:layout_height="48dp"     android:layout_alignparentend="true"     android:layout_below="@+id/recycler_view_entry_fields">      <imageview         android:id="@+id/image_view_delete_entry"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerinparent="true"         android:src="@drawable/ic_delete_black_24dp" />      </relativelayout>  </relativelayout> 

java code (using butterknife library):

@onclick(r.id.card_view) public void lauchformsactivity() {     intent formsactivityintent = new intent(cardview.getcontext(), formsactivity.class);     formsactivityintent.putextra(baseactivity.public_id, entry.getpublicid());     formsactivityintent.putextra(baseactivity.survey_id, surveyid);     cardview.getcontext().startactivity(formsactivityintent); }  @onclick(r.id.view_click_interceptor) public void lauchformsactivity2() {     lauchformsactivity(); } 

if you're ok losing scroll , item clickability, add view beloew recyclerview

<android.support.v7.widget.recyclerview   android:id="@+id/recycler_view_entry_fields"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_below="@+id/text_view_entry_status"   android:layout_margintop="16dp"/> <view   android:id="@+id/view_click_interceptor"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_below="@+id/text_view_entry_status"   android:layout_margintop="16dp"   android:background="@android:color/transparent"/> 

and in activity, viewclickinterceptor java-object of above view

viewclickinterceptor.setonclicklistener(new view.onclicklistener() {   @override public void onclick(final view v) {     // stuff   } }); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -