我試圖將List<>
從活動傳遞到片段。不相容的類型:列表<FollowUser>無法轉換爲ArrayList <String>
點擊imageView時, onClick事件觸發對服務器的調用,該服務器接受單擊imageView的用戶的userId和要查看的用戶配置文件的userId。我有一個接口,該接口將從服務器獲取響應,然後發送到一個新的片段類。我遇到的問題是我無法通過該軟件包通過List<>
。
這是片段類的newInstance
和參數我試圖跨越
public static HomeUserProfileFragment newInstance(String postTotal, String followersTotal
, String followingTotal, List<UploadPost> uploadPostList, List<FollowUser> followersList, List<FollowUser> followingList) {
HomeUserProfileFragment fragment = new HomeUserProfileFragment();
Bundle args = new Bundle();
args.putString(POST_TOTAL, postTotal);
args.putString(FOLLOWERS_TOTAL, followersTotal);
args.putString(FOLLOWING_TOTAL, followingTotal);
args.putStringArrayList(UPLOAD_POST_LIST,uploadPostList);
args.putStringArrayList(FOLLOWERS_LIST,followersList);
args.putStringArrayList(FOLLOWING_LIST, followingList);
fragment.setArguments(args);
return fragment;
}
派雖然這是Activity類,上述片段是從調用。
@Override
public void onClickUserProfile(String post, String followers, String following, List<UploadPost> uploadPostList, List<FollowUser> followersList, List<FollowUser> followingList) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, HomeUserProfileFragment.newInstance(post, followers, following,uploadPostList,followersList,followingList))
.addToBackStack(null)
.commit();
}
所以我收到以下錯誤:
Error:(56, 50) error: incompatible types: List<UploadPost> cannot be converted to ArrayList<String>
Error:(57, 48) error: incompatible types: List<FollowUser> cannot be converted to ArrayList<String>
Error:(58, 49) error: incompatible types: List<FollowUser> cannot be converted to ArrayList<String>
'args.putStringArrayList'不以工作列表不是** StringArrayList ** –