package com.example.sdtg.sdsw
import java.io.IOException
import java.util.ArrayList
import java.util.HashMap
import java.util.List
import java.util.Map
import.org.ksoap2.SoapEnvelope
import org.ksoap2.SoapFault
import org.ksoap2.serialization.SoapObject
import org.ksoap2.serialization.SoapSerializationEnvelope
import org.ksoap2.transport.HttpTransportSE
import org.xmlpull.v1.XmlPullParserException
import android.os.AsyncTask
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.app.Activity
import android.content.Intent
import android.view.Menu
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.Button
import android.widget.ListView
import android.widget.SimpleAdapter
import android.widget.TextView
import android.widget.Toast
public class ListActivity extends Activity {
// 命名空间
// String nameSpace = "http://tempuri.org/"
// 调用核圆启的方法名称
// String methodName = "GetSjSearch"
// EndPoint
// String endPoint = "http://192.168.0.145/webservice2/gswebservice.asmx"
// SOAP Action
// String soapAction = "http://tempuri.org/GetSjSearch"
// List<Map<String, Object>>mList
ListView ListV
HashMap<String, Object>map = new HashMap<String, Object>()
private List<Map<String,String>>listItems
SimpleAdapter mListAdapter
String name="腔槐"
String addr=""
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list)
listItems = new ArrayList<Map<String,String>>()
ListV=(ListView)findViewById(R.id.ListView01)
Handler indicate = new Handler()
//获取主改如页面传的值
final Intent data = getIntent()
name=data.getStringExtra("Name")
addr=data.getStringExtra("Addr")
new NetAsyncTask().execute()
ListV.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?>arg0, View arg1, int arg2,
long arg3) {
//获得选中项的HashMap对象
TextView viewtmc = (TextView) arg1.findViewById(R.id.textListmc)
TextView viewdz = (TextView) arg1.findViewById(R.id.textlistdz)
TextView viewid = (TextView) arg1.findViewById(R.id.textlistid)
//String playerChanged = c.getText().toString()
Bundle bundle = new Bundle()
bundle.putString("Name", viewtmc.getText().toString())
bundle.putString("Addr", viewdz.getText().toString())
bundle.putString("ID", viewid.getText().toString())
final Intent data = getIntent()
data.putExtras(bundle)
//跳转回MainActivity
//注意下面的RESULT_OK常量要与回传接收的Activity中onActivityResult()方法一致
ListActivity.this.setResult(RESULT_OK, data)
//关闭当前activity
ListActivity.this.finish()
}
})
}
class NetAsyncTask extends AsyncTask<Object, Object, String>{
@Override
protected void onPostExecute(String result) {
if (result.equals("success")) {
mListAdapter = null
mListAdapter = new SimpleAdapter(ListActivity.this, listItems, R.layout.item,new String[]{"title", "info", "img"}, new int[]{R.id.textListmc, R.id.textlistdz, R.id.textlistid})
ListV.setAdapter(mListAdapter)
}
super.onPostExecute(result)
}
@Override
protected String doInBackground(Object... params) {
// 命名空间
String nameSpace = "http://tempuri.org/"
// 调用的方法名称
String methodName = "GetSjSearch"
// EndPoint
String endPoint = "http://192.168.0.145/webservice2/gswebservice.asmx"
// SOAP Action
String soapAction = "http://tempuri.org/GetSjSearch"
// 指定WebService的命名空间和调用的方法名
SoapObject rpc = new SoapObject(nameSpace, methodName)
// 设置需调用WebService接口需要传入的两个参数mobileCode、userId
rpc.addProperty("name", name)
rpc.addProperty("address", addr)
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11)
// SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12)
envelope.bodyOut = rpc
// 设置是否调用的是dotNet开发的WebService
envelope.dotNet = true
// 等价于envelope.bodyOut = rpc
envelope.setOutputSoapObject(rpc)
HttpTransportSE transport = new HttpTransportSE(endPoint)
try {
// 调用WebService
transport.call(soapAction, envelope)
} catch (Exception e) {
e.printStackTrace()
}
SoapObject object
// 开始调用远程方法
try {
object = (SoapObject) envelope.getResponse()
int count = object.getPropertyCount()
// 得到服务器传回的数据
int count1 = object.getPropertyCount()
if(count1>0)
{
for (int i = 0i <count1i++) {
Map<String,String>listItem = new HashMap<String, String>()
SoapObject soapProvince = (SoapObject)object.getProperty(i)
listItem.put("title", soapProvince.getProperty("DJXX_NSRMC").toString())
listItem.put("info", soapProvince.getProperty("DJXX_ZCDJ").toString())
//listItem.put("img", soapProvince.getProperty("DJXX_NSRSBH").toString())
listItems.add(listItem)
}}
} catch (IOException e) {
e.printStackTrace()
//return "IOException"
}
return "success"
}
}
}
用for循环啊!int size = list.size()
for(int i = 0i <sizei++) {
//假设list中你侍绝旅存放的是User对宏拦象,当然其他老凳的也可以的!
User user = list.get(i)
System.out.println(user.getName())
System.out.println(user.getTelephonNum())
...
}
public static void main(String[] args) {//初始化数据
List<String>allList = new ArrayList<String>()
allList.add("学指洞生A、语文、90分、第一学期")
allList.add("学生B、语文、80分、第一学期")
allList.add("学生A、英语、90分、第一学期")
allList.add("学生A、数学、90分、第一学期")
allList.add("学生B、英语、80分、第一学期")
allList.add("学生A、语文、90分、第二学期")
allList.add("学生B、数学、80分、第一学期")
allList.add("学生B、英语、80分、羡颤第二学期")
allList.add("学生A、数学、90分、第二学期")
allList.add("学生B、语文、80分、第二学期")
//定义姓名、学期、科目 数组
List<String>stuList = new ArrayList<String>()
List<String>subjList = new ArrayList<String>()
List<String>termList = new ArrayList<String>()
boolean stuContained = false
boolean subjContained = false
boolean termContained = false
//从allList中 加载相上述三个类别,如果固定兄逗败的话,可以手动指定
for (String string : allList) {
String[] strs = string.split("、")
stuContained = false
subjContained = false
termContained = false
if(stuList.size()<=0) stuContained = false
else{
for (String string2 : stuList) {
if(string2.equals(strs[0])){
stuContained = true
break
}
}
}
if(!stuContained)
stuList.add(strs[0])
if(subjList.size()<=0) subjContained = false
else{
for (String string2 : subjList) {
if(string2.equals(strs[1])){
subjContained = true
break
}
}
}
if(!subjContained)
subjList.add(strs[1])
if(termList.size()<=0) termContained = false
else{
for (String string2 : termList) {
if(string2.equals(strs[3])){
termContained = true
break
}
}
}
if(!termContained)
termList.add(strs[3])
}
//构建结果数组
List<String>results = new ArrayList<String>()
String temp = ""
for (String string : stuList) {
temp ="姓名:"+string
for (String string2 : termList) {
temp += ",学期:"+string2
int score = 0
for (String string3 : subjList) {
temp+= ","+string3+":"
for (String string4 : allList) {
String[] temps = string4.split("、")
if(temps[0].equals(string) &&temps[1].equals(string3)&&temps[3].equals(string2)){
temp+= temps[2]
score += Integer.parseInt(temps[2].substring(0, temps[2].length()-1))
}
}
}
String[] temp2 = temp.split(",")
temp += ",总分:" + score +"分"
results.add(temp)
temp ="姓名:"+string
}
}
//输出结果
for (String string : results) {
System.out.println(string)
}
}
只是一种方案,又很多情况不确定,如果list中的数据可以作为javabean设置会方便些,如果数据是在数据库中的,那么使用sql语句会方便很多(上面的做法实际上是模拟了sql语句)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)