-6

Like the title says, I want to create a button within the app. I'm currently trying to make a planning/agenda app in android studio, that lets you create groups/events for multiple people. E.g. a button called 'add group' should create a new button under the other groups, wich all open a new generated intent with the events. (I will also need this 'layout creating' for the events)

Edit: I figured out how to generate the button, but I've still got no clue how to generate the onclicklisteners for the generated buttons. Does anyone have a solution for this?

1 Answers1

0

I've not fully tested it yet, but this seems to work:

addGroup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Button myButton = new Button(getBaseContext());
            myButton.setText("New Group");

            LinearLayout layoutOne = findViewById(R.id.base);
            LinearLayout.LayoutParams layoutOneParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layoutOne.addView(myButton, layoutOneParams);
        }
    });