-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?

2
  • 1
    how about making a button already in the design file and using the power of VISIBILITY GONE ... and playing with it in java when required just call setVisibility Commented Jan 7, 2018 at 21:07
  • Hmm, good idea. I'll definately keep it in mind. Although, I feel like there should be an other way. Commented Jan 7, 2018 at 21:12

1 Answer 1

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);
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.