我有一个按钮,当我单击它时,该表单将在表单上添加更多的 edittext (我正在使用 addView )。当我需要“添加更多商品”时,就像订单。
单击“保存”按钮时,如何获得所有edittext值?
View moreItem = inflater.inflate(R.layout.add_item, (LinearLayout) findViewById(R.id.linearItem), false);
final LinearLayout linearForm = (LinearLayout)findViewById(R.id.linearItem);
linearForm.addView(moreItem);
编辑文本位于R.layout.add_item
内部答案 0 :(得分:0)
在将editText
至addView()
添加到父视图时,可以通过运行循环来获取所有editText值。在“提交”按钮clickListener内,添加以下代码:
int count = parentLayout.getChildCount();
String[] editTextValues = new String[count];
for (int i = 0; i < count; i++) {
View view = parentlayout.getChildAt(i);
if (view instanceof EditText) {
EditText edittext = (EditText) view;
editTextValues[i] = editText.getText().toString();
}
}
答案 1 :(得分:0)
感谢所有回复。
我创建一个clickcount
变量以计算每个添加按钮的点击次数。
我已经用
editText.setTag("et"+clickcount); //When I add more button
并进行for循环
for (int i = 1; i <= clickcount; i++) {
editText= resultView.findViewWithTag("et"+i);
String text= editText.getText().toString();
}
感谢 jitesh mohite 使用getTag()的想法
答案 2 :(得分:-1)
8083
最终列表edittext = new ArrayList <>(); 按钮addbutton; 将每个值存储在列表中,并在需要的位置进行检索
apiVersion: v1
data:
my.databag.1: need_triage
kind: ConfigMap
metadata:
name: my-service-env-variables
namespace: api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: my-service
name: my-service-service-deployment
namespace: api
spec:
replicas: 1
template:
metadata:
annotations:
traffic.sidecar.istio.io/excludeOutboundIPRanges: 0.0.0.0/0
labels:
app: my-service-service-deployment
spec:
containers:
- env:
- name: my.variable
valueFrom:
secretKeyRef:
key: my_token
name: my.variable
envFrom:
- configMapRef:
name: my-service-env-variables
image: imaagepath:tag
name: my-service-pod
ports:
- containerPort: 8080
name: mysvcport
resources:
limits:
cpu: 700m
memory: 1.8Gi
requests:
cpu: 500m
memory: 1.7Gi
---
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: api
spec:
ports:
- port: 8083
protocol: TCP
targetPort: mysvcport
selector:
app: my-service-service-deployment
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-service-ingress
namespace: api
spec:
gateways:
- http-gateway
hosts:
- my-service.example.com
http:
- route:
- destination:
host: my-service
port:
number: 8083
---
apiVersion: v1
items:
- apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
clusterName: ""
creationTimestamp: 2018-11-07T13:17:00Z
name: http-gateway
namespace: api
resourceVersion: "11778445"
selfLink: /apis/networking.istio.io/v1alpha3/namespaces/api/gateways/http-gateway
uid: 694f66a4-e28f-11e8-bc21-0ac9e31187a0
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*.example.com'
port:
name: http
number: 80
protocol: HTTP
- hosts:
- '*.example.com'
port:
name: tomcat-http
number: 8083
protocol: HTTP
kind: List
metadata:
resourceVersion: ""
selfLink: ""
}}