{"id":5605,"date":"2014-04-03T21:36:52","date_gmt":"2014-04-03T21:36:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/03\/findviewbyid-in-fragment-android-collection-of-common-programming-errors\/"},"modified":"2014-04-03T21:36:52","modified_gmt":"2014-04-03T21:36:52","slug":"findviewbyid-in-fragment-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/03\/findviewbyid-in-fragment-android-collection-of-common-programming-errors\/","title":{"rendered":"findViewById in fragment android-Collection of common programming errors"},"content":{"rendered":"<p>I realise this is an old question, but the prevailing answer leaves something to be desired.<\/p>\n<p>The question is not clear what is required of <code>imageView<\/code> &#8211; are we passing it back as the view, or merely saving a reference for later?<\/p>\n<p>Either way, if the <code>ImageView<\/code> is coming from the inflated layout, the correct way to do this would be:<\/p>\n<pre><code>public class TestClass extends Fragment {\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n        View v = inflater.inflate(R.layout.testclassfragment, container, false);\n        ImageView imageView = (ImageView)v.findViewById(R.id.my_image);\n        return v;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I realise this is an old question, but the prevailing answer leaves something to be desired. The question is not clear what is required of imageView &#8211; are we passing it back as the view, or merely saving a reference for later? Either way, if the ImageView is coming from the inflated layout, the correct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5605","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5605"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5605\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}