不同Activity中的Java/Android ArrayList [英] Java / Android ArrayList in different Activity
问题描述
我正在尝试让 Arraylist 在 Android 上的另一个活动中工作.一切都很好.数组列表已创建,但是,我无法让 Intent 工作.
I'm trying to get an Arraylist to work in another Activity on Android. All is well. The arrray list is created, however, I cannot get Intent to work.
有什么方法可以让数组列表指向另一个变量?
What way is there to get an arraylist to another variable?
这是我用来生成 arrayList 的代码:
Here is the code I'm using to generate the arrayList:
public List<Contact> getAllContacts() {
List<Contact> ContactpList = new ArrayList<Contact>();
我将如何在其他活动中使用此数组列表?
How will I go about making this arraylist available in my other activities?
推荐答案
如果你有数组列表,这是你的活动:
This is your activity were you have array list Right:
public List<Contact> getAllContacts() {
List<Contact> ContactpList = new ArrayList<Contact>();
现在当你调用另一个活动然后像这样发送数组对象:
now when u call another activity then send the array object like this:
Intent intent = new Intent(youractivity.this,youractivity.class);
intent.putExtra("ContactpList ", ContactpList );
startActivity(intent);
现在在您调用的活动中获取此数组,并且您想获取该数组:
now get this array in the activity which you have called and were u want to get the array:
ArrayList<String> resultArray = getIntent().getStringArrayListExtra("ContactpList ");
希望它对你有用.
这篇关于不同Activity中的Java/Android ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!