Guest User

Untitled

a guest
Aug 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Access custom view properties after inflation in Android
  2. @Override
  3. public void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.levelbrowser);
  6. LinearLayout uttonLayout = (LinearLayout)findViewById(R.id.ButtonLayout);
  7. LevelBrowserButton button1 = new LevelBrowserButton(this, "Level 1");
  8. ButtonLayout.addView(button1);
  9. }
  10.  
  11. public LevelBrowserButton(Context context, String name)
  12. {
  13. super(context);
  14. LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  15. View layout = inflater.inflate(R.layout.levelbrowser_button, this);
  16.  
  17. TextView nameTextView = (TextView) layout.findViewById(R.id.NameTextView);
  18. // nameTextView = null!
  19. NameTextView.setText("test"); // This will throw an exception
  20.  
  21. }
Add Comment
Please, Sign In to add comment