Android Development: How To Get All EditText Children of a ViewGroup?

安稳与你 提交于 2019-12-06 07:54:41

You would need to call findViewById on each of the LinearLayouts. If you do this, you can set the same ID for each EditText.

 LinearLayout ll = //Your Layout this can be any Linear or Relative layout 
                     //in which you added your spinners at runtime ;

    int count = ll.getChildCount();
    for(int i =0;i<count;i++)
    {
        View v = ll.getChildAt(i);
        if(v instanceof Spinner)
        {
            // you got the spinner
            EditText s = (EditText) v;
            Log.i("Item selected",s.getText().toString());
        }
    }

findViewById returns only the first view with the given id. You're going to have to traverse the view hierarchy yourself, at least until you get down to each horizontal linear layout. You'll find the methods ViewGroup.getChildCount() and ViewGroup.getChildAt(int) useful for this.

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