将特定对象的数组列表从活动传递到另一个活动中的片段

时间:2016-10-18 16:52:07

标签: java android android-fragments arraylist

我有一个SubAccount的arraylist,SubAccount就是这个类:

class SubAccount {

private String username;
private String uniqueKey;
private String accountPictureString;

public SubAccount() {
}

SubAccount(String username, String uniqueKey, String accountPictureString) {
    this.username = username;
    this.uniqueKey = uniqueKey;
    this.accountPictureString = accountPictureString;
}

public void setAccountPictureString(String accountPictureString) {
    this.accountPictureString = accountPictureString;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

String getAccountPictureToString() {
    return accountPictureString;
}

String getUniqueKey() {
    return uniqueKey;
}

public void setUniqueKey(String uniqueKey) {
    this.uniqueKey = uniqueKey;
}
}

所以我需要做的是将这个arraylist从一个活动(LoginActivity)传递到另一个活动中的片段(ProfileViewFragment)(MainTabsActivity)

所以我找到了一种方法将数组从MainTabsActivity传递给片段,方法是将arraylist变量设为public并在onCreateView方法中使用这行代码:

ArrayList<SubAccount> subAccountsList = (ArrayList<SubAccount>) ((MainTabsActivity) getActivity()).subAccountsList;

所以现在我需要将arraylist从第一个活动(LoginActivity)传递给片段活动(MainTabsActivity)

谢谢你!

0 个答案:

没有答案