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 9060341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:12:16+00:00 2026-06-16T15:12:16+00:00

I m very new to Android. I want to create a dynamic OnClick button

  • 0

I m very new to Android.

I want to create a dynamic OnClick button functionality.

enter image description here

OnClick of “+” above , it should create a other layer , like this below.

enter image description here

My confusion , my entire design UI is in layout.xml.

How we can we include another layer in our UI on OnClick of “+” button.

Any input would be helpful.

Thanks !!!

  • 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-06-16T15:12:17+00:00Added an answer on June 16, 2026 at 3:12 pm

    In your XML have one Vertical Linear Layout to add and remove EditTexts at runtime, Here I have shown you code I have used in my demos. To handle and maintain the usage.

    Onclick of your Add and Minus button click

        public void onClick(View view) {
            super.onClick(view);
            switch (view.getId()) {
    
            case R.id.btnadd:
                createTextview(counter);
                counter++;
                if (counter > 3) {
                    btnAdd.setVisibility(View.GONE);
                    btnRemove.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.btnremove:
                removeView(counter);
                txtoption[counter - 1] = null;
                counter--;
                if (counter < 3) {
                    btnAdd.setVisibility(View.VISIBLE);
                    btnRemove.setVisibility(View.GONE);
                }
    
                break;
            }
        }
    

    Functions to create and remove view

    private void createTextview(int index) {
        txtoption[index] = new EditText(this);
        txtoption[index].setSingleLine(true);
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        param.bottomMargin = 10;
        txtoption[index].setLayoutParams(param);
        txtoption[index].setBackgroundResource(R.drawable.textbox);
        txtoption[index].setTypeface(ttfDroidSherif);
        lnpolloptions.addView(txtoption[index]);
    
    }
    
    private void removeView(int index) {
        lnpolloptions.removeView(txtoption[index - 1]);
    }
    

    Your vertical LinearLayout to contain all the edittext childs

    LinearLayout lnpolloptions = (LinearLayout) findViewById(R.id.lnpolloptions);
    

    Arrays of edittext to be created of removed at runtime

    private EditText[] txtoption = new EditText[4];
    

    Onclick of submit to get value from each textbox

                int length = txtoption.length;
                for (int i = 0; i < length; i++) {
                    if (txtoption[i] != null) {
                        Log.i("Value",""+txtoption[i].getText());
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm very new to android development, and want to create an app with
I'm very new on Android development. I want to create and start an activity
I am very new to android and I am developing this app which allows
i m new to this android application development i would be very much grateful
I am very new to android development.... i have created an app and want
I am very new to android. My project requires me to create a list
Hy guys, I am new to android but very enthusiastic to create my first
I am very new to Android development and Java. Have read around but I'm
I'm still very new to Android, but I am trying to keep up by
I am very new with android development. My app has a lot of views/Activity

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.