不会在ArrayAdapter中创建ParseRelation

时间:2014-12-15 16:54:03

标签: android parse-platform android-arrayadapter parserelation

我试图在Card对象和用户对象之间创建一个解析关系。当用户点击自定义arrayadapter中的连续按钮时,我会看到"已保存"消息,但在Parse databrowser上添加了关系!

这是自定义arrayadapter中的代码

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();

    }


}

0 个答案:

没有答案