Note that there are some explanatory texts on larger screens.

plurals
  1. POcreate N number of Edittext on button click
    primarykey
    data
    text
    <p>I want to create Edittext one below one on a button click.So i tried the following code.</p> <pre><code> private LinearLayout mLayout; private EditText mEditText; private Button mButton; int k = -1; int flag; int ss=0; ArrayList&lt;String&gt; applnserverinstnos = new ArrayList&lt;String&gt;(); EditText textView[] = new EditText[100]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLayout = (LinearLayout) findViewById(R.id.linearLayout); mEditText = (EditText) findViewById(R.id.editText); mButton = (Button) findViewById(R.id.button); mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub k++; flag=k; final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, 50); lparams.setMargins(20, 20, 20, 0); textView[flag] = new EditText(AddEditBoxActivity.this); textView[flag].setLayoutParams(lparams); textView[flag].setId(flag); applnserverinstnos.add(flag,Integer.toString(flag)); textView[flag].addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub String c = s.toString(); // read Content applnserverinstnos.add(flag,c); System.out.println("insno "+applnserverinstnos.get(flag)); } }); mLayout.addView(textView[flag]); } }); TextView textView = new TextView(this); Button b2= (Button)findViewById(R.id.button1); b2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub for(int i = 0;i&lt;=k;i++) { System.out.println("applserver "+i+".."+applnserverinstnos.get(i)); } } }); } </code></pre> <p>This creates the edittext one below one.I tried creating 3 edittext.But when i try to enter texts into edit text it throws following error.</p> <pre><code>06-13 12:44:47.686: E/AndroidRuntime(1665): java.lang.IndexOutOfBoundsException: Invalid index 3, size is 0 </code></pre> <p>Please help me to find it. Thank You.</p> <p><strong>EDIT</strong></p> <p>after adding <code>applnserverinstnos.add(flag,Integer.toString(flag));</code> it is not throwing error but the text changed in edittext one is not storing in position one instead it is storing in last position</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload