0

我确实检查了一些关于如何检查editext是否为空的答案,我申请了但它不起作用。可能是因为我在这里通过 c# json WCF 将 JSON 数据发送到数据库

DefaultHttpClient httpClient = new DefaultHttpClient();
                      HttpPut httpPut= new HttpPut("http://localhost:4806/Service1.svc/UpdateData/Result");
                      httpPut.setHeader("Accept", "application/json");
                      httpPut.setHeader("Content-type", "application/json");


                     JSONStringer getdat = new JSONStringer()
                            .object()
                                .key("pd")
                                    .object()
                                        .key("ID").value(txtid.getText().toString())
                                        .key("Name").value(txtname.getText().toString())
                                        .key("Project").value(txtproject.getText().toString())

                                        .key("Result").value(txttotal.getText().toString())
                                    .endObject()
                                .endObject();


StringEntity entity = new StringEntity(getdat.toString(),"UTF-8");
                        entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));


                        entity.setContentType("application/json");

                        httpPut.setEntity(entity);

if((txtid.length()==0)&&(txtname.length()==0)&&(txtproject.length()==0)&&(txttotal.length()==0))  // Modification done here
                         {
                             Toast t =Toast.makeText(this, "Please enter all fields", Toast.LENGTH_LONG);
                             t.show();   
                         }
                          else
                      {
                              HttpResponse response = httpClient.execute(httpPut);
                              Log.d("WebInvoke", "Saving : " + response.getStatusLine().getStatusCode()); 
                              Toast.makeText(this, response.getStatusLine().getStatusCode() + "\n", Toast.LENGTH_LONG).show() ;

                      }

我正在为字符串实现它,我也想对 int 字段使用空检查,但我是 android 新手,不知道该怎么做。这是 int 字段

h=Integer.parseInt(txtviva.getText().toString());
                s=Integer.parseInt(txtpres.getText().toString());
                x=Integer.parseInt(txtconfi.getText().toString());
                y=Integer.parseInt(txtsystem.getText().toString());
                  z= h+s+x+y;
                  txttotal.setText(Integer.toString(z));

感谢大家的帮助。

4

0 回答 0