How to get data from each dynamically created EditText in Android?

后端 未结 5 1088
盖世英雄少女心
盖世英雄少女心 2020-11-27 11:29

I have successfully created EditTexts depending on the user input in Android, and also I have assigned them unique ID\'s using setId() method.

Now wha

5条回答
  •  感动是毒
    2020-11-27 11:39

    You can also do like this by taking an Array of EditText. You should store all references to all EditTexts:

    EditText ed[] = new EditText[count];    
    for (int i = 0; i < count; i++) {   
    
        ed[i] = new EditText(Activity2.this);
    
        ed[i].setBackgroundResource(R.color.blackOpacity);
        ed[i].setId(id);   
        ed[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        linear.addView(ed[i]);
    }
    

    and you can use for loop to get the value from the EditText .

     for(int i = 0; i < ed.length; i++){
    
           Log.d("Value ","Val " + ed[i].getText());
      }
    

提交回复
热议问题