Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the individual texts from edittexts in a loop

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 444
    Answer it

    Please i have a for loop which creates edittext according to what the user types in. It displays the edittexts in a linearlayout.  What i want to do is to get each of the texts from the edittexts and store it in an arraylist
     This is the for loop.

    for (i = 0; i < length; i++) {
        editText = new EditText(MainActivity.this);
        editText.setId(i + 1);
        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setText("Input" + " " + (i + 1));
        listLayout.addView(editText);
        editTextCollection.add(editText);
    
    }
    
    I tried adding each editTexts to the ArrayList editTextCollection but i keep getting an error java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: