Answer the question
In order to leave comments, you need to log in
How to pass an arraylist to a fragment?
How to pass an arraylist to a fragment?
In MainActivity I create and partially fill
ArrayList<Wishbone> wishbones = new ArrayList<Wishbone>();
mWishbonePagerAdapter = new WishbonePagerAdapter(getSupportFragmentManager(), this, wishbones);
FragmentPagerAdapter
public class Wishbone
{
public int getImgLeft() {
return imgLeft;
}
public void setImgLeft(int imgLeft) {
this.imgLeft = imgLeft;
}
public int getImgRight() {
return imgRight;
}
public void setImgRight(int imgRight) {
this.imgRight = imgRight;
}
public int getVubRez() {
return vubRez;
}
public void setVubRez(int vubRez) {
this.vubRez = vubRez;
}
public int getLeftRez() {
return leftRez;
}
public void setLeftRez(int leftRez) {
this.leftRez = leftRez;
}
public int getRightRez() {
return rightRez;
}
public void setRightRez(int rightRez) {
this.rightRez = rightRez;
}
public int getLeftVote() {
return leftVote;
}
public void setLeftVote(int leftVote) {
this.leftVote = leftVote;
}
public int getRightVote() {
return rightVote;
}
public void setRightVote(int rightVote) {
this.rightVote = rightVote;
}
public ImageView getImageLeft() {
return imageLeft;
}
public void setImageLeft(ImageView imageLeft) {
this.imageLeft = imageLeft;
}
public ImageView getImageRight() {
return imageRight;
}
public void setImageRight(ImageView imageRight) {
this.imageRight = imageRight;
}
int imgLeft;
int imgRight;
int vubRez;
int leftRez;
int rightRez;
int leftVote;
int rightVote;
ImageView imageLeft;
ImageView imageRight;
Wishbone(int _imgLeft, int _imgRight, int _vubRez, int _leftRez, int _rightRez, int _leftVote, int _rightVote, ImageView _imageLeft, ImageView _imageRight) {
imgLeft = _imgLeft;
imgRight = _imgRight;
vubRez = _vubRez;
leftRez = _leftRez;
rightRez = _rightRez;
leftVote = _leftVote;
rightVote = _rightVote;
imageLeft = _imageLeft;
imageRight = _imageRight;
}
}
Answer the question
In order to leave comments, you need to log in
Well, first of all, the Wishbone class must implement the Parcelable interface . AndroidStudio should be easy to help with this, well, plus dig a little into the documentation on how to use this interface. Otherwise, you won't be able to push this ArrayList into an Intent, in this case.
Further, everything is simple. For example, you create an ArrayList collection, pass it to the Intent as an Extra (putExtra() method).
Parse the Intent in the target Activity/Fragment and pull out your collection using the getParcelableArrayList("KEY_WHICH_YOU_SPECIFIED_WHEN_PUT_THE_COLLECTION_IN_EXTRA")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question