我的活动中有一份清单,需要把清单交给下一次活动。
private List<Item> selectedData;
I tried putting this in intent by :
intent.putExtra("selectedData", selectedData);
但它没有发挥作用。 可做些什么?
我的活动中有一份清单,需要把清单交给下一次活动。
private List<Item> selectedData;
I tried putting this in intent by :
intent.putExtra("selectedData", selectedData);
但它没有发挥作用。 可做些什么?
您必须首先将<代码>List具体类型。 <代码>List本身是一个接口。
If you implement the Parcelable
interface in your object then you can use the putParcelableArrayListExtra()
method to add it to the Intent
.
和评论中提到的排他性一样,如果你把标语列入你的序列,那就变得非常容易。 然后,你可以把它放到你可以带去的布局。 例如:
class ExampleClass implements Serializable {
public String toString() {
return "I am a class";
}
}
... */ Where you wanna create the activity /*
ExampleClass e = new ExampleClass();
ArrayList<ExampleClass> l = new ArrayList<>();
l.add(e);
Intent i = new Intent();
Bundle b = new Bundle();
b.putSerializeable(l);
i.putExtra("LIST", b);
startActivity(i);
i think ur item should be parcelable. and you should use arraylist instead of list. then use intent.putParcelableArrayListExtra
这是我的工作。
//first create the list to put objects
private ArrayList<ItemCreate> itemsList = new ArrayList<>();
//on the sender activity
//add items to list where necessary also make sure the Class model ItemCreate implements Serializable
itemsList.add(theInstanceOfItemCreates);
Intent goToActivity = new Intent(MainActivity.this, SecondActivity.class);
goToActivity.putExtra("ITEMS", itemsList);
startActivity(goToActivity);
//then on second activity
Intent i = getIntent();
receivedItemsList = (ArrayList<ItemCreate>) i.getSerializableExtra("ITEMS");
Log.d("Print Items Count", receivedItemsList.size()+"");
for (Received item:
receivedItemList) {
Log.d("Print Item name: ", item.getName() + "");
}
我希望它也为你工作。
每个人都说,你可以使用可乘飞机,但无人提到,你只能把价值投向可乘飞机,而不是列入名单。
intent.putExtra("selectedData", (Serializable) selectedData);
Core s lists implementations already implement Serializable, so you re not bound to a specific implementation of list, but remember that you still can catch ClassCastException.
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...