A. android中如何在两界面间传递下面的集合
intent啊 intent是android的运输大队长
Intent newIntent = new Intent();
newIntent.setClass(this, another.class);
List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
Bundle bundle = new Bundle();
bundle.putSerializable(”data“, listData );
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);
在another类中的oncreate()方法取
List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
List<Map<String, Object>> listData= (List) bundle.getSerializable(”data“);
}
大概是这个样子,祝你顺利
B. android 如何将listview的每个item中的值传到另一个Activity中
你可以把从服务器中获取的数据封装到一个类中间中,然后通过Parcelable打包一下。。。。。
再把封装的类装到一个ArrayList中
在通过Intent 和bundle把你打包的ArrayList传过去。。。。你在另一个Activity中接受就ok了
我曾经在做一个音乐播放器的时候就是把listview中就是这样把音乐信息都传过去
传值:Intent intent ;
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("musics",musics<是指的那个ArrayList名字>);
intent = new Intent(this, 另外的Activity名字.class);
接受值:另外一个Activity中
Intent myintent = getIntent();
Bundle bundle = myintent.getExtras();
ArrayList<封装类名> musics = bundle.getParcelableArrayList("music");
这是我个人的解决方法,不知道能不能帮到你。。。。。。
C. android 怎么取list数据
按以下代码可获取到list数据:
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 = 0; i < count1; i++) {
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";
}
}
}
D. android 怎么在activity之间传递List 类型的数据
Intent 传值可以传递对象,但是比较麻烦,要序列化
给你一种建议,将这个List转成JSON字符串
另外一个Activity再将这个字符串返序列即可
JSON与java对象相互转换google提供了一个非常牛X的工具Gson
用法非常简单,一行代码搞定
E. 请问下, Intent传输数据的时候 如何能传输List<Object> 里面是个对象
先把List对象加到Bundle里去,在传递Bundle对象
F. 如何用bundle传递arraylist<overlayitem>的数组
例子
在用多线程的时候,会需要在Message中传递自己定义的Arraylist
但是呢,Messge的数据传递必须要用Bundle
所以需要将自定义的ArrayList<Object>放入Bundle
解决方法是用Bundle.putParcelableArrayList(list)
当然不能直接把list放入bundle中,必须经过加工
方法如下:
Message msg = new Message();
Bundle bundle = new Bundle();
ArrayList list = new ArrayList(); //这个list用于在budnle中传递 需要传递的ArrayList<Object>
list.add(ArrayList<Object>)
bundle.putParcelableArrayList("list",list)
msg.setDate(bundle)
Handler.sendMessage(msg)
取的时候:
ArrayList list = bundle.getParcelableArrayList("list");
list2= (List<Object>) list.get(0);//强转成你自己定义的list,这样list2就是你传过来的那个list了。
G. android bundle可以传递arraylist吗
可以的
H. android ArrayList在activity之间传值的问题
如果list_s是List的引用,那么你需要强转;如果list_s是ArrayList,那么不用强转。
如果你看Android代码的话 会发现ArrayList是这么定义的:
public class ArrayList<E> extends AbstractList<E> implements Cloneable, Serializable, RandomAccess {
他跟List(接口)不同。。
I. android Parcelable如何传递boolean 与List<E>类型的变量
想传递boolean比较简单,可以用Bundle直接putBoolean
对于List类型,需要E是继承了parcelable接口
并且List实际类型要是ArrayList才可以.
调用putParcelableArrayList(String key, ArrayList<? extends Parcelable> list);
关于继承Parcelable接口
需要完成以下内容:
1,声明该类class MyParcelable implements Parcelable;
2,创建Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>()
{
需要实现
public MyParcelable createFromParcel(Parcel source)
{
//例如MyParcelable有String name;
MyParcelable p = new MyParcelable();
p.name = source.readString();
//所有成员都要处理.
}
public MyParcelable[] newArray(int size)
{
return new MyParcelable[size];//这样就可以了
}
}
J. Android Activity间传二维数组问题
1楼说的很对,在另一个Activity接收,我再补充一下,
String[] strArray = getIntent().getSerializableExtra("intArray")
也可以用这种方式传递对象、map集合等,传递对象的实体类要实现系列化。接受就用上面的方法,传过来的是什么对象,就强转一下就好了。