Skip to content

Instantly share code, notes, and snippets.

@matthew-carroll
Created July 6, 2019 11:04
Show Gist options
  • Save matthew-carroll/cec83e27aac493d313a525871d526395 to your computer and use it in GitHub Desktop.
Save matthew-carroll/cec83e27aac493d313a525871d526395 to your computer and use it in GitHub Desktop.
Example of setting a View ID programatically in Android.
public class SomeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.some_layout);
MyView myView = new MyView(this);
myView.setId(R.id.desired_id);
addView(myView);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment