1

我正在尝试在 Card 对象和用户对象之间创建解析关系。当用户在自定义 arrayadapter 中连续单击类似按钮时,我会看到“已保存”消息,但不会在 Parse 数据浏览器上添加关系!

这是自定义数组适配器中的代码

public class CardAdapter extends ArrayAdapter<ParseObject> {

    public static final String TAG = CardAdapter.class.getSimpleName();

    protected Context mContext;
    protected List<ParseObject> mCards;
    protected ParseRelation<ParseObject> mCardsLikeRelation;
    protected ParseUser mCurrentUser;




    public CardAdapter(Context context, List<ParseObject> cards) {
        super(context, R.layout.card_item, cards);

        mContext = context;
        mCards = cards;
        mCurrentUser =  ParseUser.getCurrentUser();


    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;




        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.card_item, parent, false);
            holder = new ViewHolder();
            holder.CardImageView = (ImageView) convertView.findViewById(R.id.cardImage);
            holder.CardContent = (TextView) convertView.findViewById(R.id.cardText);

            holder.CardLikeButton = (Button)convertView.findViewById(R.id.likeButton);


            convertView.setTag(holder);
        }
        else{

            holder = (ViewHolder) convertView.getTag();
        }

        final ParseObject card = mCards.get(position);


        if(card != null) {

            mCardsLikeRelation = mCurrentUser.getRelation("cardLikesRelation");

            holder.CardContent.setText(card.getString("content"));



            holder.CardLikeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, card.getObjectId(),
                            Toast.LENGTH_LONG).show();
                    mCardsLikeRelation.add(card);

                    mCurrentUser.saveInBackground(new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            if (e != null) {
                                Log.e(TAG, e.getMessage());
                            }
                            else{

                                Log.e(TAG, "saved");
                            }
                        }
                    });
                }
            });

        }



        return convertView;
    }


    private static class ViewHolder{

        ImageView CardImageView;
        TextView CardContent;
        Button CardLikeButton;
        TextView CardLikes;
        ProgressBar progress;

    }

    public void refill(List<ParseObject> cards){

        mCards.clear();
        mCards.addAll(cards);
        notifyDataSetChanged();

    }


}
4

0 回答 0