Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:05:29+00:00 2026-05-22T21:05:29+00:00

I have created button’s dynamically by using RelativeLayout.Now i have to implement the listener

  • 0

I have created button’s dynamically by using RelativeLayout.Now i have to implement the listener of the dynamic button. How can i do this, And another thing i am creating multiple button’s so plz tell me how can i do this?

This is my code

public class CreateButton extends Activity {

    int top=60,bottom=350, i;
    int s = 1,iddelete = 1,idedit=1;
    RelativeLayout rl;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        rl = (RelativeLayout)findViewById(R.id.edit_r);

        // Create Bed Room
        Button Btn_BedRoom = (Button)findViewById(R.id.bed);
        Btn_BedRoom.setOnClickListener(ListenrOf_BedRoom);

    }

 // Listener Of Create Bed Room
    private OnClickListener ListenrOf_BedRoom = new OnClickListener()
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            CreateRoom();
            i+=35;
        }
    };


    public void CreateRoom()
    {       
        final Button delete = new Button(this);
        delete.setText("delete");
        delete.setBackgroundResource(R.drawable.cross);

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);             
        lp.setMargins(120, top+i, 0, bottom-i);  
        delete.setHeight(5);
        delete.setWidth(5);
        delete.setLayoutParams(lp);
              delete.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        CreateRoom();           
    }
    });                   
              rl.addView(delete);


        Button BtnEdit = new Button(this);
        RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);             
        lp1.setMargins(150,top+i,0,bottom-i);
        BtnEdit.setBackgroundResource(R.drawable.edit);
        BtnEdit.setHeight(5);
        BtnEdit.setWidth(5);
        BtnEdit.getRight();
        BtnEdit.setLayoutParams(lp1);
        rl.addView(BtnEdit);

        TextView tv = new TextView(this);
        RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp2.setMargins(180,top+i,0,bottom-i);
        tv.setText("Bed Room " + s++);
        tv.setLayoutParams(lp2);
        rl.addView(tv);

    };


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:05:30+00:00Added an answer on May 22, 2026 at 9:05 pm
    Button bt = new Button(this.getApplicationContext());
    bt.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          // do something when the button is clicked
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created button dynamically now i want to set parameter such as (layout_marginTop
I have created a custom button using this code setup : function(ed) { ed.addButton('Tittle',
i have a table which contains a bunch of dynamically created radio button lists,
I have created radio button like this: @foreach (LoanQuestionIncludesStatement statement in item.Statements) { _question
i have created dynamic button with code below, the button caption is too long
i have some problem.. i have created a dynamic button in a table view.
I have created button without any border using LWUIT resource editor. I am able
I have created a custom UIButton (UIButton subclass) for my application. Within this button's
I have created a button in my screen's XML like this: <Button android:text=Lets Get
I have created a button. Now I want to do: A single click of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.