{"id":194,"date":"2016-09-07T20:04:58","date_gmt":"2016-09-08T03:04:58","guid":{"rendered":"http:\/\/jasonflaherty.com\/blog\/?p=194"},"modified":"2016-09-07T20:06:29","modified_gmt":"2016-09-08T03:06:29","slug":"android-recyclerview-onclick-events","status":"publish","type":"post","link":"https:\/\/jasonflaherty.com\/blog\/2016\/09\/07\/android-recyclerview-onclick-events\/","title":{"rendered":"Android RecyclerView OnClick Events"},"content":{"rendered":"<p>This one boggled me for the longest time. However, you can simply add your on click events right in your RecyclerView Adapter.<\/p>\n<pre class=\"\">TextView tv1,tv2;\r\n.....\r\npublic void onBindViewHolder(MyViewHolder myviewholder, final int i){\r\n     myviewholder.tv1.setText(myview.get(i).tvdata1);\r\n     myviewholder.tv2.setText(myview.get(i).tvdata2);\r\n     .... \r\n     myviewholder.tv.setOnClickListener(new View.OnClickListener() {\r\n\r\n @Override\r\n public void onClick(View v) {\r\n      Intent intent = new Intent(context, NewActivity.class);\r\n      Bundle bundle = new Bundle();\r\n      bundle.putSerializable(\"data1\", incidents.get(i).tvdata1);\r\n      bundle.putSerializable(\"data2\", incidents.get(i).tvdata2);\r\n      intent.putExtras(bundle);\r\n      context.startActivity(intent);\r\n }\r\n .... \r\n}<\/pre>\n<p>I was overthinking this stuff. Anyone have any issues with this? Seems to work just fine for me.<\/p>\n<p><em>Featured Image: <a href=\"http:\/\/ciandesign.deviantart.com\/art\/Cyan-Mountains-483185522\">http:\/\/ciandesign.deviantart.com\/art\/Cyan-Mountains-483185522<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This one boggled me for the longest time. However, you can simply add your on click events right in your RecyclerView Adapter.<\/p>\n<p class=\"excerpt-link\"><a href=\"https:\/\/jasonflaherty.com\/blog\/2016\/09\/07\/android-recyclerview-onclick-events\/\">&sim;&nbsp;Continue Reading&nbsp;&sim;<\/a><\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false,"jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[93],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/jasonflaherty.com\/blog\/wp-content\/uploads\/2015\/12\/cyan_mountains_by_ciandesign-d7zocc2-e1451412319818.png?fit=1200%2C675&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5OfD9-38","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/posts\/194"}],"collection":[{"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":1,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions\/196"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonflaherty.com\/blog\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}