如何通过bean类一个活动在Android上另一个活动 [英] How to pass bean class one activity to another activity on android

查看:146
本文介绍了如何通过bean类一个活动在Android上另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,这是我的列表视图onClicklister。

Hi this is my listview onClicklister.

当我点击列表中的项目,我通过它从bean类一个活动越来越像下面另一个活动的数组列表。

when i click the list item , I pass the the arraylist which is getting from bean class one activity to another activity like below.,

但我想知道我们可以通过bean类下一个活动?

But i want to know can we pass the bean class to next activity?

listViewRoutes.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
          long arg3) {
        RouteBean bean = routeList.get(arg2);
        ArrayList<Double> fromLatitude = bean.getFromLatitude();
        ArrayList<Double> fromLongitude= bean.getFromLongitude();
        ArrayList<Double> toLatitude = bean.getToLatitude();
        ArrayList<Double> toLongitude= bean.getToLongitude();
        Intent intent =new Intent("MapActivityView");
        intent.putExtra("fromLon", fromLongitude);
        intent.putExtra("fromLat", fromLatitude);
        intent.putExtra("toLat", toLatitude);
        intent.putExtra("toLon", toLongitude);
        startActivity(intent);
      }
    });

如果我通过了路线豆,我得到的值的下一个活动。

if i pass the "Route Bean", i get the values on next activity.

是否有可能通过bean类?

Is it possible to pass the bean class ?

推荐答案

您可以通过使用对象 Parcelable 类..

You can pass your object using Parcelable class..

像,

public class RouteBean implements Parcelable {

}

一旦你有你的对象实施 Parcelable 这是将它们放入你的意图与 putExtra的只是一个问题()

Once you have your objects implement Parcelable it's just a matter of putting them into your Intents with putExtra():

Intent i = new Intent();
i.putExtra("object", Parcelable_Object);

然后你可以拉他们回来用 getParcelableExtra()

Intent i = getIntent();
RouteBean bean = (RouteBean) i.getParcelableExtra("object");

有关更多信息看这太问题<一href="http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android">How传递对象从一个活动到另一个机器人

For more info look at this SO question How to pass object from one activity to another in Android

这篇关于如何通过bean类一个活动在Android上另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆