Search This Blog

Sunday, July 24, 2011

SOAPy Trois

A simple change to add an EditText into the view and wire it up with the following code and we are now passing user entered text into the web service call. The only thing that took a few moments of thought was how to get a String out of an edit text since getText() returns an editable. I tried getString() and it worked. Code changes to SOAPy are below:

        buttonGoodbye.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                final EditText txt = (EditText) findViewById(R.id.editText1);
                String name = txt.getText().toString();
                if (name.length() == 0) name = "No name";

                new CallServiceTask(HelloAndroid.this).execute(
                        GOODBYE_OPERATION_NAME, name);
            }
        });
        final Button buttonHello = (Button) findViewById(R.id.button2);
        buttonHello.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                final EditText txt = (EditText) findViewById(R.id.editText1);
                String name = txt.getText().toString();
                if (name.length() == 0) name = "No name";

                new CallServiceTask(HelloAndroid.this).execute(
                        HELLO_OPERATION_NAME, name);
            }
        });


So, that was easy. On to the more complex data types.

No comments: