Wednesday, February 19, 2014

How to Set findViewById for View Via programmatically in android

How to Set findViewById for View Via programmatically in android


This post about how to set the id for view . When you are creating a view from programmatically.

Create id in the resource
<resources>
      <item type="id" name="my_btn" />
     <item type="id" name="my_imageView" />


</resources>


Set the id for view in Activity Class or where ur creating view

Button btn = new Button(context);
ImageButton image_btn = new ImageButton(context);
btn.setId(R.id.my_btn);
image_btn.setId(R.id.my_imageView);
             
Then Find the view using findViewById .  

image_btn = (ImageButton) findViewById(R.id.my_imageView);
btn = (Button) findViewById(R.id.my_btn);             



No comments:

Post a Comment

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...