Backendless - Android:从列表

时间:2016-04-28 16:26:25

标签: android list backendless

我想从列表中删除用户,但它似乎无法正常工作。 我的项目中有一个Feeds.class,我有:

public class Feeds {
private List<BackendlessUser> usersThatLike;

public List<BackendlessUser> getUsersThatLike() {
return usersThatLike;
}

public void setUsersThatLike(List<BackendlessUser> usersThatLike) {
this.usersThatLike = usersThatLike;
}
}

在我的适配器中,我尝试删除当前用户:

feed.getUsersThatLike().remove(Backendless.UserService.CurrentUser);

除了保存Feeds类和handleResponse之外,我在日志窗口中将列表打印为字符串,当前用户仍然在列表中。 无法弄清楚它有什么问题。 需要帮忙。 感谢

适配器

    public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.FeedsHolder> {

        private List<Feeds> list;
        private Context context;
        private static List<Long> selectedIds;
        List<BackendlessUser> backendlessUserList;
        private List<Comments> cake = new ArrayList<>();
        private static String TAG = "MainActivity";

        public FeedAdapter(Context context, List<Feeds> list) {
            this.context = context;
            this.list = list;

        }

        @Override
        public FeedsHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.feed_item, parent, false);

            final FeedsHolder holder = new FeedsHolder(view);

            //Query

            QueryOptions options = new QueryOptions();

            options.setRelated(Arrays.asList("usersThatLike"));

            BackendlessDataQuery query = new BackendlessDataQuery();

            query.setQueryOptions(options);

            Backendless.Data.of(Feeds.class).find(query, new AsyncCallback<BackendlessCollection<Feeds>>() {

                @Override

                public void handleResponse(BackendlessCollection<Feeds> response) {
                    myFeeds = response;
                    String userId = Backendless.UserService.CurrentUser().getObjectId();
                    for (Feeds feed : response.getData()) {
                        feed = list.get(holder.getAdapterPosition());

                        List<BackendlessUser> likedUsers = feed.getUsersThatLike();
                        backendlessUserList = likedUsers;
                        for (BackendlessUser user : likedUsers)
                            if (user.getObjectId().equals(userId)) {
                                setBackground(holder.like, ContextCompat.getDrawable(context, R.drawable.ic_favorite_black_24dp));
                            } else if (!user.getObjectId().equals(userId)) {
                                setBackground(holder.like, ContextCompat.getDrawable(context, R.drawable.ic_favorite_border_black_24dp));
                            }
                    }

                }

                @Override

                public void handleFault(BackendlessFault backendlessFault) {

                }

            });
            return holder;
        }

        @Override
        public void onBindViewHolder(final FeedsHolder holder, final int position) {
            //Starting Feeds
            final Feeds feeds = list.get(position);

            holder.like.setBackground(ContextCompat.getDrawable(context, R.drawable.ic_favorite_border_black_24dp));

holder.like.setOnClickListener.......
//Skipped for brevity
feeds.getUsersThatLike().remove(Backendless.UserService.CurrentUser);
//SAVE FEEDS HERE
}
}

            //Name
            holder.name.setText(feeds.getOwner());

        @Override
        public int getItemCount() {
            return list.size();
        }

        public class FeedsHolder extends RecyclerView.ViewHolder {
            //Setup Views
            CardView card;
            TextView name;
             ImageView like;

            public FeedsHolder(View itemView) {
                super(itemView);

                //Assign views by ID
                card = (CardView) itemView.findViewById(R.id.cv);
                name = (TextView) itemView.findViewById(R.id.commenter);
                like = (ImageView) itemView.findViewById(R.id.like);
            }
        }
    }

0 个答案:

没有答案