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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:45:28+00:00 2026-06-19T03:45:28+00:00

I am creating a add contact activity. There will be only one edit text

  • 0

I am creating a add contact activity. There will be only one edit text and a button (+), when click on button then another edit text should be added and previous button should change into (-). By this method i want to add and remove edit text fields.Some thing like this. I am doing like this but not able to achieve that i want. Any idea?

public class TextField extends Activity {

Context con;
TableLayout table;
TableRow tr[] = new TableRow[6];
EditText txt[] = new EditText[6];
//ImageView img[] = new ImageView[5];
Button img[]=new Button[6];
int count ;
int lastDeletedIndex;
int lastPopulatedIndex;
boolean isDel;
public void onCreate(Bundle obj) {
    super.onCreate(obj);
    // Log.d("","On Create");
    con = this;
    count = 1;

    table = new TableLayout(this);
    tr[count] = new TableRow(this);
    tr[count].setId(count);
    tr[count].setLayoutParams(new TableRow.LayoutParams(    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    txt[count] = new EditText(this);
    txt[count].setId(count);
    txt[count].setText("1");
    txt[count].setMaxLines(1);
    txt[count].setWidth(160);

        img[count] = new Button(this);
        img[count].setId(count);
        img[count].setText("+");
        img[count].setBackgroundResource(R.drawable.add);
        img[count].setPadding(5, 7, 20, 0);


    tr[count].addView(txt[count]);
    tr[count].addView(img[count]);
    tr[count].setPadding(20, 20, 0, 0);

    img[count].setOnClickListener(new OnClick(img[count]));

    table.addView(tr[count]);
    setContentView(table);

}

class OnClick implements OnClickListener {

    View view;

    Button addIcon;

    public OnClick(View view) {

        this.addIcon = (Button) view;

    }

    @Override
    public void onClick(View arg0) {

            int id=addIcon.getId();
        if(addIcon.getText().toString().equals("-"))
        {

            if ((id >1  )) {
                isDel=true;
                count=id;
                lastDeletedIndex=id;
                txt[count]=null;
                img[count]=null;
                table.removeView(tr[count]);
                tr[count]=null;
                Log.d("", "Cancel img Id" + addIcon.getId());
                }       


        } else {
            if (count <5) {
                if(table.getChildCount()!=5)
                {
                    addIcon.setBackgroundDrawable(getResources().getDrawable(R.drawable.delete));
                    addIcon.setText("-");


                addIcon.setId(count);
                if(!isDel) {
                    count++;
                }else
                {
                    count=lastDeletedIndex;
                }


                tr[count] = new TableRow(con);
                tr[count].setId(count);


                    img[count] = new Button(con);
                img[count].setId(count);
                img[count].setBackgroundDrawable(getResources().getDrawable(R.drawable.add));
                img[count].setText("+");
                img[count].setPadding(3, 7, 20, 0);
                img[count].setOnClickListener(new OnClick(img[count]));

                txt[count] = new EditText(con);
                txt[count].setId( count);
                txt[count].setText(""+count);
                txt[count].setMaxLines(1);
                txt[count].setWidth(160);

                tr[count].addView(txt[count]);

                tr[count].addView(img[count]);

                tr[count].setPadding(20, 20, 0, 0);
                table.addView(tr[count]);
                setContentView(table);
                isDel=false;

                lastPopulatedIndex=count;

                Log.d("", "Cancel img Id" + addIcon.getId());
                }
            } else
                ShowDialog.showAlert("Info","You can't add more than 5 contacts!", con);
        }

    }
}
  • 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-19T03:45:29+00:00Added an answer on June 19, 2026 at 3:45 am
    private void addEditView() {
            // TODO Auto-generated method stub
              LinearLayout li=new LinearLayout(this);
              EditText et=new EditText(this);
              Button b=new Button(this);
    
              b.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                    int pos=(Integer) v.getTag();
                    mainLayout.removeViewAt(pos);
    
                }
            });
    
              b.setTag((mainLayout.getChildCount()+1));
        }
    

    call this function when you click on a addEditText button.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an Add-in for Outlook 2010. Once the button is clicked, the
Im creating a game an want to be able to add there score so
I am creating an Contact Us button which would allow the User to contact
I'm creating a web page that user can send pm , receive it,add contact,response
I find myself creating Add/Edit/Delete/List GUI's so often that I'm sick and tired of
I create one new application.i add the contact from address book see the code
I'm creating an Outlook add-in that can save selected emails to an external database.
I am creating a custom add-in ribbon for MS Word 2010. I wanted to
I am creating an Excel add-in written in VB.NET. I would like to bind
I am creating a chart control chart1.ChartAreas.Add(area); chart1.series.add(time); //loop //get values of a and

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.