我想要一个不允许重复值的列表对象,Set<String>
是我需要的。
然而,它不能通过bundle或extra传递给其他活动,因为它不是serializable
?
我怎样才能做到这一点?
Set<String> foo = new HashSet<String>();
Intent i = new Intent();
i.putExtra("key", foo);
startActivity(..., i);
修改
而不是..
Set<String> foo = new HashSet<String>();
改变这个..
HashSet<String> foo = new HashSet<String>();
解决问题感谢大家。
答案 0 :(得分:0)
你在说什么......
public class
HashSet
extends AbstractSet<E>
implements Set<E> Cloneable Serializable
哈希集是可序列化的...你不需要传入一个Set,只需使用HashSet OR 如果你想STILL使用Set作为数据类型,那么当它的时候把它转换为HashSet通过意图。
http://developer.android.com/reference/java/util/HashSet.html
答案 1 :(得分:-1)
您可以这样做: -
在您要发送数据的活动中
ArrayList userlist = new ArrayList();
Intent intent = new Intent(context,Dashboard.class); intent.putExtra(&#34; userlist&#34;,userlist);
您想要获取数据的活动
protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
userlist = (ArrayList<User>) getIntent().getSerializableExtra("userlist");
}
用户Bean
public class User实现Serializable {
/**
*
*/
private static final long serialVersionUID = -3200348961839049924L;
/**
*
*/
private String name;
private String phoneNo;
private String emailId;
}