【问题标题】:soap web service in androidandroid中的肥皂网络服务
【发布时间】:2015-03-16 10:09:37
【问题描述】:
Activity extends Activity {
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            button = (Button) findViewById(R.id.button);

         button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                  t1 = ((EditText) findViewById(R.id.editText1)).getText().toString().trim();
                     t2 = ((EditText) findViewById(R.id.editText2)).getText().toString().trim();

                     webAccess();



                }
            });
           }


        public void webAccess(){
            thread = new Thread(){
                public void run(){
                    try{
                        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                         request.addProperty("LoginID",t1);
                        request.addProperty("Password",t2);
                        request.addProperty("Token","21220150145");
                        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                        envelope.dotNet = true;
                        envelope.setOutputSoapObject(request);
                        System.out.println(request);
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();


                        System.out.println(response);


                        String xml = response.toString();

                        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                                .parse(new InputSource(new StringReader(xml)));




                        NodeList statNodes = doc.getElementsByTagName("Return"); //parent tag
                        if (statNodes.getLength() > 0) {
                            Element stat = (Element)statNodes.item(0);
                            // System.out.println(stat.getElementsByTagName("status")
                            //       .item(0).getTextContent()); // child tag
                            Webresponse = stat.getElementsByTagName("status")
                                    .item(0).getTextContent();


                        }


                    }

                    catch(Exception e){
                        e.printStackTrace();
                    }

                    handler.post(createUI);
                }
            };

            thread.start();
        }


        final Runnable createUI = new Runnable() {


            public void run(){
    //          Toast.makeText(getApplicationContext(),
    //                    Webresponse, Toast.LENGTH_LONG).show(); 


                    Intent i=new Intent(CheckLoginActivity.this,HomeActivity.class);

                startActivity(i);

                }
            }
        };

        }

      iam new to soap web service from above code i have done login web service from this if i entered username,password am getting the correct toast message i want to navigate next page how to do that thanks in advance.

如果我输入了正确的密码,我会在 toast 中成功,我输入的密码我会失败。

所以我需要的是,如果我输入正确的用户名和密码,它会转到下一页,否则用户名和密码不正确。所以请大家帮我看看。

【问题讨论】:

    标签: android web-services soap


    【解决方案1】:

    您必须检查“Webresponse”,如下所示。

    if(Webresponse.equals("success"){
    //open target activity
    }else{
    //show error message
    }
    

    【讨论】:

    • 我试过了,但它只显示吐司成功,不会进入下一个活动
    • 我再次将你的代码放入 run 方法中,它只显示成功的 toast 消息没有移动到下一个活动
    • 在 Runnable 类之前移除 final 并尝试
    • Runnable createUI = new Runnable() { public void run(){ Toast.makeText(getApplicationContext(), Webresponse, Toast.LENGTH_LONG).show(); textview.setText(Webresponse); if(Webresponse.equals("SUCCESS")){ Intent i=new Intent(CheckLoginActivity.this,HomeActivity.class);开始活动(一); } else{ //显示错误信息 }
    • 而不是 handler.post(createUI)。使用 CheckLoginActivity.this.runOnUiThread(createUI);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2017-01-16
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多