1.主Activity
3.main.xml文件
4.item.xml
package com.nantian.app;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class Tel3Activity extends Activity implements OnClickListener,OnItemClickListener{
/** Called when the activity is first created. */
private Button submit;
private ListView list;
private ShowAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new ShowAdapter(this);
submit = (Button) findViewById(R.id.submit);
list = (ListView) findViewById(R.id.list);
list.setOnItemClickListener(this);
submit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(this, "===", Toast.LENGTH_LONG).show();
String[] str = {"11","22","33"};
ArrayAdapter a = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,str);
list.setAdapter(adapter);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(this, "hi,thank for u click!", Toast.LENGTH_LONG).show();
}
}
2.BaseAdapter
package com.nantian.app;
import java.io.IOException;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ShowAdapter extends BaseAdapter {
private Context c;
private LayoutInflater inflater;
private TextView test ;
Object result = null;
SoapObject soapObject = null;
Vector<SoapObject> o;
/**
* 调用WebService
*/
public ShowAdapter(Context context) {
super();
this.c = context;
this.inflater = LayoutInflater.from(context);
SoapObject request = new SoapObject("http://service.workSituation.wsCommon.zcpt.nantian.com","queryWcbSlcminByNm");
//request.addProperty("ennm","永昌退水闸");
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelop.bodyOut = request;
HttpTransportSE ht = new HttpTransportSE("http://10.64.8.27/CommonService/services/SluiceSituationService?wsdl");
try {
ht.call(null, envelop);
if(envelop.getResponse()!=null){
o = (Vector<SoapObject>) envelop.getResponse();
//soapObject = (SoapObject) envelop.getResponse();
//result = (Object) soapObject.getProperty("ennm");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ShowAdapter() {
super();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return o.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Model model = new Model();
if(convertView == null){
inflater = LayoutInflater.from(c);
convertView = inflater.inflate(R.layout.item, null);
model.test = (TextView) convertView.findViewById(R.id.item0);
model.ennm = (TextView) convertView.findViewById(R.id.item1);
model.ennmcd = (TextView) convertView.findViewById(R.id.item2);
model.bldt = (TextView) convertView.findViewById(R.id.item3);
}else{
model = (Model) convertView.getTag();
}
if(position%2==0){
convertView.setBackgroundColor(Color.BLUE);
}
model.test.setText("-----"+o.get(position).getProperty("ennm")+"站点基本信息"+"-----");
model.ennm.setText("站名:"+o.get(position).getProperty("ennm"));
model.ennmcd.setText("站号:"+o.get(position).getProperty("ennmcd"));
model.bldt.setText("其他信息:"+o.get(position).getProperty("gatsiz"));
//model.ennm.setText("站名:"+soapObject.getProperty("ennm").toString());
//model.ennmcd.setText("站号:"+soapObject.getProperty("ennmcd").toString());
//model.bldt.setText("统计日期:"+soapObject.getProperty("bldt").toString());
//model.bldt.setText("统计日期:"+"2012-1-1");
//model.ennm.setText("xyz");
convertView.setTag(model);
return convertView;
}
public class Model{
TextView test,ennm,bldt,ennmcd;
}
}
3.main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="显示数据"
/>
<Button
android:id="@+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="提交数据"
android:layout_gravity="right"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
4.item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/item0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/item0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/item3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>