如何通过自定义对象的包? [英] How to pass custom object in Bundle?

查看:93
本文介绍了如何通过自定义对象的包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我自己的自定义对象成束:

 叠B =新包();
                STMessage消息=(STMessage)a.getAdapter()的getItem(位置)。
                b.putObject(消息,消息);
 

我得到的错误:

 的方法putObject(字符串,对象)是未定义的类型包
 

解决方案

一种方法是让你的自定义对象实现Parcelable接口,并使用 Bundle.putParcelable / Bundle.getParcelable

I am trying to pass my own custom object into a bundle:

Bundle b = new Bundle();
                STMessage message = (STMessage)a.getAdapter().getItem(position);
                b.putObject("message",message);

I get the error:

The method putObject(String, Object) is undefined for the type Bundle

解决方案

One way is to have your custom object implement the Parcelable interface and use Bundle.putParcelable/Bundle.getParcelable

这篇关于如何通过自定义对象的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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