Having trouble binding a ksoap object to an ArrayList in Android

Posted by Maskau on Stack Overflow See other posts from Stack Overflow or by Maskau
Published on 2010-04-13T13:36:01Z Indexed on 2010/04/13 17:03 UTC
Read the original article Hit count: 1283

Filed under:
|
|
|

I'm working on an app that calls a web service, then the webservice returns an array list. My problem is I am having trouble getting the data into the ArrayList and then displaying in a ListView. Any ideas what I am doing wrong? I know for a fact the web service returns an ArrayList. Everything seems to be working fine, just no data in the ListView or the ArrayList.....Thanks in advance!

EDIT: So I added more code to the catch block of run() and now it's returning "org.ksoap2.serialization.SoapObject".....no more no less....and I am even more confused now...

package com.maskau;

import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.*;
import android.os.*;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.view.View;
import android.view.View.OnClickListener;


public class Home extends Activity implements Runnable{

/** Called when the activity is first created. */
public static final String SOAP_ACTION = "http://bb.mcrcog.com/GetArtist";
public static final String METHOD_NAME = "GetArtist";
public static final String NAMESPACE = "http://bb.mcrcog.com";
public static final String URL = "http://bb.mcrcog.com/karaoke/service.asmx";
String wt;
public static ProgressDialog pd;
TextView text1;
ListView lv;
static EditText myEditText;
static Button but;
private ArrayList<String> Artist_Result = new ArrayList<String>();



@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    myEditText = (EditText)findViewById(R.id.myEditText);
    text1 = (TextView)findViewById(R.id.text1);
    lv = (ListView)findViewById(R.id.lv);
    but = (Button)findViewById(R.id.but);

    but.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            wt = ("Searching for " + myEditText.getText().toString());
            text1.setText("");
            pd = ProgressDialog.show(Home.this, "Working...", wt , true, false);
            Thread thread = new Thread(Home.this);
            thread.start();
        }
    }
    );
}

public void run()
{
        try
     {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo pi = new PropertyInfo();
            pi.setName("ArtistQuery");
            pi.setValue(Home.myEditText.getText().toString());
            request.addProperty(pi);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            AndroidHttpTransport at = new AndroidHttpTransport(URL);
            at.call(SOAP_ACTION, envelope);
            java.util.Vector<Object> rs = (java.util.Vector<Object>)envelope.getResponse();
            if (rs != null)
            {
                for (Object cs : rs)
                {
                    Artist_Result.add(cs.toString());
                }
            }
        }

     catch (Exception e)
        {
         // Added this line, throws "org.ksoap2.serialization.SoapObject" when run
            Artist_Result.add(e.getMessage());      
      }

     handler.sendEmptyMessage(0);
}
private Handler handler = new Handler()
{
    @Override
    public void handleMessage(Message msg)
    {
        ArrayAdapter<String> aa;
    aa = new ArrayAdapter<String>(Home.this, android.R.layout.simple_list_item_1, Artist_Result);
    lv.setAdapter(aa);
    try
    {
        if (Artist_Result.isEmpty())
        {
               text1.setText("No Results");
        }
        else
        {

               text1.setText("Complete");
               myEditText.setText("Search Artist");
        }
    }
    catch(Exception e)
    {
    text1.setText(e.getMessage());
    }
    aa.notifyDataSetChanged();
    pd.dismiss();
    }
};
}

© Stack Overflow or respective owner

Related posts about android

Related posts about ksoap2