Android SOAP解析xml列表视图
我正在通过SOAP创建XML解析。Android 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);
}
});
}
}
}
}
编辑代码一样below..I我不知道让你尝试..
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);
}
//}
}
}
也是同样的错误 – user2181025 2013-03-18 06:56:51
是复制并仅粘贴 – user2181025 2013-03-18 07:02:14
user2181025复制和通过这个错误(显示什么)作为评论下面这篇文章。 – Subburaj 2013-03-18 07:03:28
请帮我任何一个 – user2181025 2013-03-18 05:51:16
我不明白什么是你的问题是? – Subburaj 2013-03-18 05:55:57
@Subburaj在这个变量我不使用,在这里无效错误即将到来我不明白我在哪里使用该变量(params),onPostExecute(Void params)请帮我 – user2181025 2013-03-18 06:00:11