How to get values from dynamically created EditText fields?

一笑奈何 提交于 2019-12-01 13:04:39

问题


I am little confused with following scenario:

I have an add button which I use it to add a number of EditText fields, when I tap on the save button I should get the values from the EditTexts.

How can I get these values from all of the EditText fields?


回答1:


You could do something like this:

Store all the EditText fields you create programmatically inside a List. So whenever you have viewGroup.add(myEditText); you would also have myList.add(myEditText);

Then when you press 'save' just loop on your list and use getText() to get the data from your EditText fields.

I'm sure there are also other ways to accomplish this ;)




回答2:


btn_no_of.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            String str1=edittext1.gettext.tostring();
                            String str2=edittext2.gettext.tostring();

        }
    });


来源:https://stackoverflow.com/questions/12506849/how-to-get-values-from-dynamically-created-edittext-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!