I have a recycleview with data and I need to transfer all the data items to another activation, how can I implement it?

  • one
    for this purpose there is an intent intent which has the peculiarity of transmitting data using put. Extrara - elik
  • I have several item with different values, you offer to transfer only one item. - OPTIMIST .KZ
  • Then you can make adjustments to your adapter. You are using its driver - elik
  • You need an adapter that will have all the data - elik
  • It is necessary to create a class inheriting from BaseAdapter and there you set all the data and put in the View view the transfer of all data - elik

2 answers 2

Why make such a crutch as in the previous answer, if any model can be made serializable ( implements Parcelable ) and transfer the entire model as a whole?

Put in intent: intent.putExtra("parcelable", myParcelables.get(position))

We take from intent: MyParcelable model = getIntent().getParcelableExtra("parcelable")

implementation example:

 public class Country implements Parcelable { private String code; private String name; private String tag; private int limit; private String image; public Country(JSONParser data) { code = data.getString("code"); name = data.getString("value"); tag = data.getString("flag"); image = data.getString("image"); if (data.contains("limit")) { limit = data.getInt("limit") - code.length(); } } public Country(Parcel in) { code = in.readString(); name = in.readString(); tag = in.readString(); image = in.readString(); limit = in.readInt(); } public static final Creator<Country> CREATOR = new Creator<Country>() { @Override public Country createFromParcel(Parcel in) { return new Country(in); } @Override public Country[] newArray(int size) { return new Country[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(code); dest.writeString(name); dest.writeString(tag); dest.writeString(image); dest.writeInt(limit); } public String getClearCode() { return code; } public String getCode() { return "+" + code; } public String getName() { return name; } public String getTag() { return tag; } public int getLimit() { return limit; } public String getImage() { return image; } } 

PS

In order not to catch a BadParcelableException when passing between activities, the Parcelable constructor must initialize the data in the same order in which they were recorded in the Parcel in the void writeToParcel(Parcel, int) method

  • Like, but it is not always better to use Parcel ... Sometimes it is better to putExtra, for example, with d - code;) - GuardFromUA

The most primitive to add a clicker and send data Here is an example implementation

Add it to the listener

  Intent intent = new Intent(getActivity(), YourNextActivity.class); intent.putExtra("movie_id_key", movies.get(position).getId); //you can name the keys whatever you like intent.putExtra("movie_rating_key", movies.get(position).getRating); //note that all these values have to be primitive (ie boolean, int, double, String, etc.) intent.putExtra("movie_release_date_key", movies.get(position).getReleaseDate); startActivity(intent) 

And you register it in a new Activity:

  String id = getIntent().getExtras().getString("movie_id_key");