20150626_Andriod_02_ListView2_列表与详细信息
android listview
参考地址:
http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html
http://xys289187120.blog.51cto.com/3361352/657171/
http://jeyechao.iteye.com/blog/1149127
F9_GridView -> Fr_02_view_s1 -> Fr_05_view_s2
************************************************************************
主表
package com.example.ht;
import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.io.IOException;
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.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.StrictMode;
import android.app.Activity;
//import android.view.Menu;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.HashMap;
public class F9_GridView extends ActionBarActivity {
private EditText et_phone;
private TextView tv_result;
private Button btn_query;
private String str_1, str_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f9_grid_view);
initView();
tv_result.setMovementMethod(ScrollingMovementMethod.getInstance());
}
///////////////////////////
private void initView() {
tv_result = (TextView) findViewById(R.id.tvResult);
et_phone = (EditText) findViewById(R.id.editText_f9_number);
btn_query = (Button) findViewById(R.id.btn_c2);
btn_query.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String phone = et_phone.getText().toString().trim();
//if ("".equals(phone) || phone.length() < 7) {
if ("".equals(phone)) {
et_phone.setText("您输入为空");
et_phone.requestFocus();
tv_result.setText("");
return;
}
getRemoteInfo(phone);
}
});
}
/**
* 查询号码段归属地的方法
*
* @param phone
* 手机号码段
*/
public void getRemoteInfo(final String phone) {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// 命名空间
String nameSpace = "http://tempuri.org/";
// 调用方法的名称
//String methodName = "selectAllCargoInfor";
String methodName = "Return_master";
// EndPoint
String endPoint = "http://192.168.1.91:8028/an_sql_test1.asmx";
// SOAP Action
// String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/selectAllCargoInfor";
String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/Return_master";
// 指定WebService的命名空间和调用方法
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// 设置需要调用WebService接口的两个参数mobileCode UserId
//soapObject.addProperty("mobileCode", phone);
//soapObject.addProperty("userId", "");
//soapObject.addProperty("Ts_01", "");
//soapObject.addProperty("Ts_02", "");
//soapObject.addProperty("Ts_03", "");
//soapObject.addProperty("Ts_06", "");
// 生成调用WebService方法调用的soap信息,并且指定Soap版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.bodyOut = soapObject;
// 是否调用DotNet开发的WebService
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(endPoint);
try {
transport.call(soapAction, envelope);
} catch (IOException e) {
//} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String result = object.getProperty(0).toString();
Message message = handler.obtainMessage();
message.obj = result;
handler.sendMessage(message);
*/
/*
SoapObject object = (SoapObject) envelope.getResponse();
//如果获取的是个集合,就对它进行下面的操作
if(object.getName()=="anyType")
{
//遍历Web Service获得的集合
for(int i=0;i<object.getPropertyCount();i++){
//MFirst m =new MFirst();
//获取单条的数据
SoapObject soapChilds =(SoapObject)soapObject.getProperty(i);
//对单个的数据进行再次遍历,把它的每行数据读取出来
for(int k=0;k<soapChilds.getPropertyCount();k++)
{
PropertyInfo propertyInfo = new PropertyInfo();
soapChilds.getPropertyInfo(k, propertyInfo);
//获取实体类的所有属性
Field[] field = m.getClass().getDeclaredFields();
//遍历所有属性
for(int j=0 ; j<field.length ; j++){
//获取属性的名字
String name = field[j].getName();
*/
/*
SoapObject result2 = (SoapObject) envelope.getResponse();
result2 = (SoapObject)result2.getProperty(1);
result2 = (SoapObject)result2.getProperty(0);
for(int i=0; i< result2.getPropertyCount(); i++ ){
HashMap<String, String> map=new HashMap<String, String>();
SoapObject soap = (SoapObject) result2.getProperty(i);
String Ts_01 =soap.getProperty("Ts_01").toString();
String Ts_02 =soap.getProperty("Ts_02").toString();
String Ts_03 =soap.getProperty("Ts_03").toString();
String Ts_06 =soap.getProperty("Ts_06").toString();
}
Message message = handler.obtainMessage();
message.obj = result2;
handler.sendMessage(message);
*/
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String result = object.getProperty(0).toString();
Message message = handler.obtainMessage();
message.obj = result;
handler.sendMessage(message);
/////////
}
}).start();
}
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
// 将WebService得到的结果返回给TextView
//tv_result.setText(msg.obj.toString());
str_1 = msg.obj.toString();
str_2 = str_1.replace("anyType{","");
str_1 = str_2.replace("}","");
str_2 = str_1.replace("string=","");
//str_1 = str_2.replace(";","\r\n");
str_1 = str_2.replace(";",",");
tv_result.setText(str_1);
/////////---s1---/////////
Intent intent = new Intent(F9_GridView.this,Fr_02_view_s1.class);
Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
bundle.putString("key_view_s1", str_1.toString());
intent.putExtras(bundle);
startActivity(intent);
/////////------/////////
/////////--s2----/////////
//Intent intent = new Intent(F9_GridView.this,Fr_05_view_s2.class);
//Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
//bundle.putString("key_view_s1", str_1.toString());
//intent.putExtras(bundle);
//startActivity(intent);
/////////------/////////
};
};
///////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.f9__grid_view, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
************************************************************************
************************************************************************
列表
package com.example.ht;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
//////////////////////////////////
import android.app.ListActivity;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
//ws//
import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.io.IOException;
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.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.StrictMode;
import android.app.Activity;
//import android.view.Menu;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.HashMap;
//ws//
//////////////////////////////////
public class Fr_02_view_s1 extends ActionBarActivity {
//////////////////////////////////
private ListView mListView = null;
private ArrayAdapter myAdapter = null;
private String str_from;
private String str_id, str_to;
//////////////////////////////////
private static String[] db_string=null;
private static final String[] COUNTRIES=new String[]{"中国","俄罗斯","英国","法国","中国","俄罗斯","英国","法国"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fr_02_view_s1);
/////////------/////////
Bundle bunde = this.getIntent().getExtras();
str_from = bunde.getString("key_view_s1").toString();
db_string =str_from.split(",");
/////////------/////////
//setContentView(R.layout.main);
//设置一个Adapter
mListView = (ListView) findViewById(R.id.listView1);//得到ListView对象的引用 /*为ListView设置Adapter来绑定数据*/
// mListView.setAdapter(new ArrayAdapter<String>(this,
// android.R.layout.simple_expandable_list_item_1, COUNTRIES));
mListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_expandable_list_item_1, db_string));
///////////////////条目选中///////////////////
///////////////////
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
//Toast.makeText(Fr_02_view_s1.this,"您选择了" + db_string[position], Toast.LENGTH_LONG).show();
str_id = db_string[position].trim();
//******************
initView();
//******************
//Toast.makeText(Fr_02_view_s1.this,"您选择了" + str_to, Toast.LENGTH_LONG).show();
/////////---s1---/////////
//Intent intent = new Intent(Fr_02_view_s1.this,Fr_05_view_s2.class);
//Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
//bundle.putString("key_view_s2", str_to);
//intent.putExtras(bundle);
//startActivity(intent);
/////////------/////////
}
});
///////////////////
}
//////////////ws////////////////
//////////////ws////////////////
//////////////ws////////////////
private void initView()
{
String phone = str_id;
getRemoteInfo(str_id);
}
//
public void getRemoteInfo(final String phone) {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// 命名空间
String nameSpace = "http://tempuri.org/";
// 调用方法的名称
//String methodName = "selectAllCargoInfor";
String methodName = "Return_R_detail";
// EndPoint
String endPoint = "http://192.168.1.91:8028/an_sql_test1.asmx";
// SOAP Action
// String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/selectAllCargoInfor";
String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/Return_R_detail";
// 指定WebService的命名空间和调用方法
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// 设置需要调用WebService接口的两个参数mobileCode UserId
//soapObject.addProperty("Ts_01", "");
soapObject.addProperty("str_Work_ID", str_id);
// 生成调用WebService方法调用的soap信息,并且指定Soap版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.bodyOut = soapObject;
// 是否调用DotNet开发的WebService
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(endPoint);
try {
transport.call(soapAction, envelope);
} catch (IOException e) {
//} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String result = object.getProperty(0).toString();
Message message = handler.obtainMessage();
message.obj = result;
handler.sendMessage(message);
/////////
}
}).start();
}
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
// 将WebService得到的结果返回给TextView
//tv_result.setText(msg.obj.toString());
String str_1, str_2;
str_1 = msg.obj.toString();
str_2 = str_1.replace("anyType{","");
str_1 = str_2.replace("}","");
str_2 = str_1.replace("string=","");
//str_1 = str_2.replace(";","\r\n");
str_1 = str_2.replace(";",",");
//tv_result.setText(str_1);
str_to = str_1;
/////////---s1---/////////
Intent intent = new Intent(Fr_02_view_s1.this,Fr_05_view_s2.class);
Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
bundle.putString("key_view_s2", str_to);
intent.putExtras(bundle);
startActivity(intent);
/////////------/////////
};
};
//////////////ws////////////////
//////////////ws////////////////
//////////////ws////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fr_02_view_s1, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
************************************************************************
************************************************************************
详细信息
package com.example.ht;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
//////////////////////////
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.ListActivity;
import android.content.Intent;
//import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import java.util.List;
//////////////////////////
//public class Fr_05_view_s2 extends ActionBarActivity {
public class Fr_05_view_s2 extends ListActivity {
// TitleList -------------
//////////////////////////
private String[] t1 = { "ID", "工号", "姓名", "部门", "工作内容"};
private String[] t2 = null;
private String[] mListTitle = null;
private String[] mListStr = null;
//private int int_close = 0;
private String str_1;
ListView mListView = null;
ArrayList<Map<String,Object>> mData= new ArrayList<Map<String,Object>>();;
//////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_fr_05_view_s2);
/////////------/////////
Bundle bunde = this.getIntent().getExtras();
str_1 = bunde.getString("key_view_s2").toString();
t2 =str_1.split(",");
/////////------/////////
//////////////////////////
//int_close = mListTitle.length + 1;
//mListTitle[int_close] = "订单编号";
//mListStr[int_close] = "退出";
//String[] name = new mListTitle[int_close];
mListTitle = insert(t1, "返回");
mListStr = insert(t2, "返回");
//////////////////////////
mListView = getListView();
int lengh = mListTitle.length;
for(int i =0; i < lengh; i++) {
Map<String,Object> item = new HashMap<String,Object>();
item.put("title", mListTitle[i]);
item.put("text", mListStr[i]);
mData.add(item);
}
SimpleAdapter adapter = new SimpleAdapter(this,mData,android.R.layout.simple_list_item_2,
new String[]{"title","text"},new int[]{android.R.id.text1,android.R.id.text2});
setListAdapter(adapter);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
if (mListTitle[position] == "返回")
{
//Intent intent = new Intent(Fr_05_view_s2.this, F9_GridView.class);
//startActivity(intent);
finish();
}
else
{
Toast.makeText(Fr_05_view_s2.this,"您选择了标题 :" + mListTitle[position] + ", "
+ " 信息 :"+mListStr[position], Toast.LENGTH_LONG).show();
}
}
});
super.onCreate(savedInstanceState);
}
//////////////string[]添加元素函数/////////////////
private static String[] insert(String[] arr, String str)
{
int size = arr.length;
String[] tmp = new String[size + 1];
System.arraycopy(arr, 0, tmp, 0, size);
tmp[size] = str;
return tmp;
}
////////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fr_05_view_s2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
************************************************************************
20150626_Andriod_02_ListView2_列表与详细信息的更多相关文章
- Django学习笔记--通用列表和详细信息视图
根据教程写完代码后,点击All books也一直跳转到index的页面 我打开了F12调试,看到点击没有出现book_list的代码,觉得应该是url的路径写得不对,但是跟教程代码对比了下,并没有发现 ...
- Display a Detail View with a List View 主子视图-列表视图与详细信息视图同时显示
In this lesson, you will learn how to display a Detail View together with a List View. For this purp ...
- GraphQL漏洞案例之获取Facebook任意用户的朋友列表和部分支付卡详细信息
Facebook有一个GraphQL endpoint,只能由Facebook的某些应用程序使用.需要用户(或页面)access_token来查询GraphQL endpoint. 这里可以将Face ...
- C#开发微信门户及应用(4)--关注用户列表及详细信息管理
在上个月的对C#开发微信门户及应用做了介绍,写过了几篇的随笔进行分享,由于时间关系,间隔了一段时间没有继续写这个系列的博客了,并不是对这个方面停止了研究,而是继续深入探索这方面的技术,为了更好的应用起 ...
- Asp.Net MVC4入门指南(9):查询详细信息和删除记录
在本教程中,您将查看自动生成的Details和Delete方法. 查询详细信息和删除记录 打开Movie控制器并查看Details方法. public ActionResult Details(int ...
- 【java 获取数据库信息】获取MySQL或其他数据库的详细信息
1.首先是 通过数据库获取数据表的详细列信息 package com.sxd.mysqlInfo.test; import java.sql.Connection; import java.sql.D ...
- struts2:上传多个文件时实现带进度条、进度详细信息的示范
上一篇文章讲了上传单个文件与上传多个文件(属性驱动)的例子.本例是上传多个文件(属性驱动),并且显示进度条.进度详细信息的示范. 在文件上传选择界面,允许用户增加.删除选择的文件,且只能上传指定类型的 ...
- 利用Scrapy爬取所有知乎用户详细信息并存至MongoDB
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者 :崔庆才 本节分享一下爬取知乎用户所有用户信息的 Scrapy 爬虫实战. 本节目标 本节要实现的内容有 ...
- 【Android Developers Training】 99. 获取联系人详细信息
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
随机推荐
- 怎么设置task的最大线程数
//-------------------------------------------------------------------------- // // Copyright (c) Mic ...
- [Reprint]C++函数前和函数后加const修饰符区别
c++中关于const的用法有很多,const既可以修饰变量,也可以函数,不同的环境下,是有不同的含义.今天来讲讲const加在函数前和函数后面的区别.比如: 01 #include<iostr ...
- 【你吐吧c#每日学习】10.29 C#字符串类型&Common operators
backslash \反斜杠 escape sequence 转义字符 double quote 双引号 new line 新行字符 Bell アラート Console.WriteLine(" ...
- Struts2 标签库讲解
要使用Struts2的标签,只需要在JSP页面添加如下一行定义即可: <%@ taglib prefix="s" uri="/struts-tags"%& ...
- 常见http代码错误原因及处理
常见的HTTP错误可以分为以下四大类.每一大类又细分为很多类小错误.当您打不开网站或者打开网站报错时首先检查您输入的网站是否有误,检查网络是否有问题或者虚拟主机的DNS是否可以解析.确定没有问题时再看 ...
- struts自定义拦截器
第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...
- paper 28 :一些常见常用数据库的下载网站集锦
做图像处理+模式识别的童鞋怎么可以没有数据库呢? 但是,如果自己做一个数据库,费时费力费钱先不说,关键是建立的数据库的公信力一般不会高,做出的算法也别人也不好比较,所以呢,下载比较权威的公共数据库还是 ...
- paper 4:支持向量机系列一: Maximum Margin Classifier —— 支持向量机简介。
支持向量机即 Support Vector Machine,简称 SVM .我最开始听说这头机器的名号的时候,一种神秘感就油然而生,似乎把 Support 这么一个具体的动作和 Vector 这么一个 ...
- paper 2:图像处理常用的Matlab函数汇总
一 图像的读写 1 imread imread函数用于读入各种图像文件,如:a=imread('e:\w01.tif') 注:计算机E盘上要有w01相应的.tif文件. 2 imwrite imwri ...
- IUS通过PLI产生fsdb波形
IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...