0

I want to add a button programmatically from the java code rather than adding it from the XML file. How can I do that?

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108

1 Answers1

0

First step is to instantiate button inside onStart(), later add the instantiated button to the ComponentContainer or setUIContent();

 @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        Button button = new Button(MainAbilitySlice.this);
        setUIContent(button);
    }
Gowtham GS
  • 478
  • 2
  • 5