本文介绍了传递一个 ArrayList<Object>从一个意图到另一个意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 ActivityA 中创建了一个 ArrayList,我想将它传递给 ActivityB.
I have created an ArrayList in ActivityA and i want to pass it to ActivityB.
活动A:
ArrayList<CardDetails> cardDetailsToPass = new ArrayList<>();
if (v.getId() == balance.getId()){
for(CardDetails cardDetails : cardDetailsArrayList){
int clientID = cardDetails.getClientID();
int cardID = cardDetails.getCardID();
int cardNo = cardDetails.getCardNo();
int balance = cardDetails.getCardBalance();
int availableBalance = cardDetails.getCardAvailableBalance();
int limit = cardDetails.getCardLimit();
int expDate = cardDetails.getExpDate();
String status = cardDetails.getStatus();
cardDetailsToPass.add(new CardDetails(clientID,cardID,cardNo,balance,availableBalance,limit,expDate,status));
Log.d("Adapter","clientID "+cardDetails.getClientID());
Log.d("Adapter","cardID "+cardDetails.getCardID());
Log.d("Adapter","cardNo "+cardDetails.getCardNo());
Log.d("Adapter","cardBalance "+cardDetails.getCardBalance());
Log.d("Adapter","cardAvailableBalance "+cardDetails.getCardAvailableBalance());
Log.d("Adapter","cardLimit "+cardDetails.getCardLimit());
Log.d("Adapter","cardExpDate "+cardDetails.getExpDate());
Log.d("Adapter","cardStatus "+cardDetails.getStatus());
}
Intent intent = new Intent(context, CardStatementActivity.class);
intent.putExtra("cardDetailsToPass",cardDetailsToPass);
context.startActivity(intent);
活动B:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_statement);
Bundle extras = getIntent().getExtras();
if(extras != null){
//get the ArrayList here
}
}
我已经尝试了一种方法,但没有成功.传递对象的 ArrayList 是否需要其他东西?
I've tried one method of doing this but with no success. Does passing an ArrayList of Objects require something else ?
推荐答案
您可以通过使用 serializable 或parcelable 传递自定义定义对象的arraylist.
You can pass the arraylist of your custom define object either by using serializable or parcelable.
使用下面的链接有很大帮助
use the below link that helps lot
Android:Parcelable 和 Serializable 的区别?
这篇关于传递一个 ArrayList<Object>从一个意图到另一个意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!