如何通过bean类一个活动在Android上另一个活动bean、Android

2023-09-04 05:02:16 作者:网名很长的女生都不是单身

你好,这是我的列表视图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");

有关更多信息看这太问题How传递对象从一个活动到另一个机器人

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