Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Access custom view properties after inflation in Android
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.levelbrowser);
- LinearLayout uttonLayout = (LinearLayout)findViewById(R.id.ButtonLayout);
- LevelBrowserButton button1 = new LevelBrowserButton(this, "Level 1");
- ButtonLayout.addView(button1);
- }
- public LevelBrowserButton(Context context, String name)
- {
- super(context);
- LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View layout = inflater.inflate(R.layout.levelbrowser_button, this);
- TextView nameTextView = (TextView) layout.findViewById(R.id.NameTextView);
- // nameTextView = null!
- NameTextView.setText("test"); // This will throw an exception
- }
Add Comment
Please, Sign In to add comment