![](/img/trans.png)
[英]How to remove duplicates value from ArrayList<CustomObject> in java
[英]How pass an ArrayList<customObject> from an intent to an other?
我的意圖是從Web服務中搜索數據。 我正試圖將這些數據從這個意圖傳遞到另一個屏幕(意圖)
尋找意圖
public void setXXX(ArrayList<XXX> xxxData) {
this.xxxs= xxxData;
if(xxxData.size() > 0)
{
Intent intent = new Intent(this, otherActivity.class);
startActivity(intent);
}else{
alert (getResources().getString(R.string.no_result));
}
}
接收者意圖
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.xxxs = (...);
setContentView(R.layout.activity_xxxlist);
this.xxxList = (ListView) findViewById(R.id.listview);
this.listView.setAdapter(new xxxDataAdapter(this,this.layoutInflator, this.xxxs));
}
我怎樣才能從第二個意圖中使用我的arrayList <>?
為了能夠通過Intents
發送對象,您必須為該對象實現Parcelable
接口。 它使用CREATOR
來編寫該對象的字符串和原始類型。
完成后,您可以在ArrayList中發送該對象,如下所示:
intent.putParcelableArrayListExtra(ArrayList<Parcelable> ... );
請參閱此方法: putParcelableArrayListExtra
在接收活動中,您可以致電:
getIntent().getParcelableArrayListExtra( String key );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.