1

私はSOAPを介してXML解析を作成しています。

jarファイルとインターネットユーザー権限が追加されました。

onPostExecuteでその変数を使用する方法

変数onPostExecuteのタイプが無効です。

その変数の使い方私はしません私を助けてください。

MainActivity.java

public class MainActivity extends ListActivity  {

// XML node keys
static final String FORMMODEL = "FormModel";
 static final String TEXT1 = "Text1";
static final String TEXT2 = "Text2";
static final String TEXT3 = "Text3";


private static final String METHOD_NAME = "HelloWorld";
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://sygnetinfosol.com/webservice.asmx";
//you can get these values from the wsdl file^

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
        new SoapRequestTask().execute();

}
private class SoapRequestTask extends AsyncTask<Void, Void, Void> {
private Object ListAdapter;
//runs on ui thread.
protected void onPreExecute() {
//display progressdialog
}
 // runs in the background thread. do not update ui from here
protected Void doInBackground(Void... params) {
//make a soap request here
SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("bSelected", true);

SoapSerializationEnvelope sse=new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.setOutputSoapObject(request);
sse.dotNet=true;

HttpTransportSE htse=new HttpTransportSE(URL);
try {
htse.call(SOAP_ACTION, sse);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}

SoapObject res=(SoapObject) sse.bodyIn;

final ArrayList<HashMap<String, String>> valuesList = new ArrayList<HashMap<String, String>>();

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(FORMMODEL);

// looping through all item nodes <item>
for (int i = 0; i < ((SoapObject) nl).getPropertyCount(); i++) {

SoapObject  namesObject = (SoapObject) res.getProperty(i);
for(int j=0;j<namesObject.getPropertyCount();j++)
{
Object objectNames=namesObject.getProperty(j);
SoapObject soapObjectText1 = (SoapObject)objectNames;
SoapObject soapObjectText2 = (SoapObject)objectNames;
SoapObject soapObjectText3 = (SoapObject)objectNames;


String sText1 = soapObjectText1.getProperty("iText1").toString();
String sText2 = soapObjectText2.getProperty("sText2").toString();
String sText3 = soapObjectText3.getProperty("sText3").toString();

// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);

// adding each child node to HashMap key => value
map.put(TEXT1, parser.getValue(e, sText1)); 
map.put(TEXT2, parser.getValue(e, sText2));
map.put(TEXT3, parser.getValue(e, sText3));

System.out.println("MY SOAP RESPONE IS"+ res.getProperty(0).toString());

// adding HashList to ArrayList
valuesList.add(map);
}
 return null;
}


 //runs on ui thread.update ui here
protected void onPostExecute(Void params1{

ListAdapter adapter = new SimpleAdapter(MainActivity.this, valuesList,R.layout.list_item,
        new String[] { TEXT1, TEXT2, TEXT3 }, new int[] {
                R.id.lat, R.id.long1, R.id.address });

setListAdapter(adapter);

ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

         HashMap<String, String> map = new HashMap<String, String>();
            map = valuesList.get(position);
        // Starting new intent
        Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
        in.putExtra(TEXT1, map.get(MainActivity.TEXT1));
        in.putExtra(TEXT2, map.get(MainActivity.TEXT2));
        in.putExtra(TEXT3, map.get(MainActivity.TEXT3));

        startActivity(in);

  }
 });

}
}
}

}
4

1 に答える 1

1

以下のようにコードを編集してください。

  package com.syg.abc;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xmlpull.v1.XmlPullParserException;

import android.app.ListActivity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity 
{

    // XML node keys
static final String FORMMODEL = "FormModel";
static final String TEXT1 = "Text1";
static final String TEXT2 = "Text2";
static final String TEXT3 = "Text3";


private static final String METHOD_NAME = "HelloWorld";
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://sygnetinfosol.com/webservice.asmx";
//you can get these values from the wsdl file^

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
            new SoapRequestTask().execute();

   }

@SuppressWarnings("rawtypes")
private class SoapRequestTask extends AsyncTask<Void, Void, ArrayList> 
{
private Object ListAdapter;
//runs on ui thread.
protected void onPreExecute() {
//display progressdialog
}
 // runs in the background thread. do not update ui from here
protected ArrayList doInBackground(Void... params) {
//make a soap request here
SoapObje request=new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("bSelected", true);

SoapSerializationEnvelope sse=new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.setOutputSoapObject(request);
sse.dotNet=true;

HttpTransportSE htse=new HttpTransportSE(URL);
try {
htse.call(SOAP_ACTION, sse);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}

SoapObject res=(SoapObject) sse.bodyIn;

final ArrayList<HashMap<String, String>> valuesList = new ArrayList<HashMap<String, String>>();

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(FORMMODEL);

// looping through all item nodes <item>
for (int i = 0; i < ((SoapObject) nl).getPropertyCount(); i++) {

SoapObject  namesObject = (SoapObject) res.getProperty(i);
for(int j=0;j<namesObject.getPropertyCount();j++)
{
Object objectNames=namesObject.getProperty(j);
SoapObject soapObjectText1 = (SoapObject)objectNames;
SoapObject soapObjectText2 = (SoapObject)objectNames;
SoapObject soapObjectText3 = (SoapObject)objectNames;


String sText1 = soapObjectText1.getProperty("iText1").toString();
String sText2 = soapObjectText2.getProperty("sText2").toString();
String sText3 = soapObjectText3.getProperty("sText3").toString();

// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);

// adding each child node to HashMap key => value
map.put(TEXT1, parser.getValue(e, sText1)); 
map.put(TEXT2, parser.getValue(e, sText2));
map.put(TEXT3, parser.getValue(e, sText3));

System.out.println("MY SOAP RESPONE IS"+ res.getProperty(0).toString());

// adding HashList to ArrayList
valuesList.add(map);
}
 return valuesList;
}
}

 //runs on ui thread.update ui here
protected void onPostExecute(ArrayList <HashMap<String, String>> valuesList)
{

@SuppressWarnings("unchecked")
ListAdapter adapter = new SimpleAdapter(MainActivity.this, valuesList,R.layout.list_item,
        new String[] { TEXT1, TEXT2, TEXT3 }, new int[] {
                R.id.lat, R.id.long1, R.id.address });

setListAdapter(adapter);

  }
//}
}
}
于 2013-03-18T06:39:25.797 に答える